<CFLOCK NAME="lockname" TIMEOUT="timeout in seconds " THROWONTIMEOUT="Yes/No"> <!--- CFML to be synchronized ---> </CFLOCK>
The CFLOCK tag single-threads access to the CFML constructs in its body. Single-threaded access implies that the body of the tag can be executed by at most one request at a time. A request executing inside a CFLOCK tag has an "exclusive lock" on the tag. No other requests are allowed to start executing inside the tag while a request has an exclusive lock. ColdFusion issues exclusive locks on a first-come first-serve basis.
Optional. Specifies the name of the lock. Only one request will be able to execute inside a CFLOCK tag with a given name. Therefore, providing the NAME attribute allows for synchronizing access to the same resources from different parts of an application. Lock names are global to a ColdFusion server. They are shared between applications and user sessions, but not across clustered servers. If the NAME attribute is not provided, ColdFusion creates an anonymous lock every time CFLOCK is used in a page.
Required. Specifies the maximum amount of time in seconds to wait to obtain an exclusive lock. If an exclusive lock can obtained within the specified period, execution will continue inside the body of the tag. Otherwise, the behavior depends on the value of the THROWONTIMEOUT attribute.
Optional. Yes or No. Specifies how timeout conditions should be handled. If the value is Yes an exception will be generated to provide notification of the timeout. If the value is No execution continues past the </CFLOCK> tag. Default is Yes.
ColdFusion Server is a multi-threaded web application server that can process multiple page requests at any given time. Use CFLOCK to guarantee that multiple concurrently executing requests do not manipulate shared data structures, files, or CFXs in an inconsistent manner. Note the following:
Note: CFLOCK uses a kernel level synchronization object that is released automatically upon timeout and/or abnormal termination of the thread that owns it. Therefore, ColdFusion will never deadlock while processing a CFLOCK tag. However, very large timeouts can block request threads for long periods of time and thus radically decrease throughput. Always use the minimum timeout value allowed.