cfthread
tag & the thread
construct. Threads are independent streams of execution, and multiple threads on a page can execute simultaneously and asynchronously, letting you perform asynchronous processing in CFML. CFML code within the cfthread
tag body executes on a separate thread while the page request thread continues processing without waiting for the cfthread
body to finish. You can allow the thread body to continue executing in the background or you can wait for it to finish.runAsync()
function or parallel Java streams using the cbStreams project. Please see our Asynchronous Programming section for information on advanced asynchronous programming.writedump() + abort
combo usually goes into ether. Logging will be your best friend and outputting logs to the console for debugging purposes.systemOutput( obj, addNewLine:boolean, doErrorStream:boolean)
- Writes the given text or complex objects to the output or error stream. Complex objects are outputted as JSON. (Lucee-only) https://cfdocs.org/systemoutput​cfdump( var="text", output="console" )
- Send the variables to the output console, even complex variables. Complex objects are outputted as JSON. https://cfdocs.org/cfdump​cflog( text, log, file, type ) or writeLog()
- Leverage the ColdFusion engine's logging facilities to send typed messages. https://cfdocs.org/cflog thread
is extremely easy, just use the construct, give it a few attributes an boom you are in multi-threaded land. In tags you can use the <cfthread>
tag.local
scopeThread
scopeAttributes
scopelocal
scope. Any variable that you define inside the thread
body without specifying a scope name prefix is in the thread local scope and cannot be accessed or modified by other threads.Thread
ScopeThread
scope contains thread-specific variables and metadata about the thread. Only the owning thread can write data to this scope, but the page thread and all other threads in a request can read the variable values in this scope. Thread scope data remains available until the page and all threads that started from the page finish, even if the page finishes before the threads complete processing. So be careful with what you store in this scope or you can create memory leaks.thread
scope or actually the name of the thread as well, which is pretty cool.thread
construct you can use the name of the thread or the thread scope, but you must reference which thread scope within it using it's name: thread.myThreadName
Thread scope
data, you must place the data in a shared location such as a shared scope or a file or database.thread
construct as a name-value pair. The CFML engine will then place those in the thread's attributes
scope so they can be used for the life of the thread.