I had the need to run a cfthread from inside another cfthread in Lucee recently. @micstriit mentioned that this was already possible in Lucee 5.1, however my project was using Lucee 4.5 and unable to upgrade at the moment.
It is fairly easy to fire off a Java thread by creating a CFC with a “void run()” method and using createDynamicProxy() to create it as an instance of “java.lang.Runnable”. Then it can be passed into a java.lang.Thread() constructor and started with “start()”. This works well, but the thread runs outside of the page context and doesn’t get access to settings like CF mappings and the “thread” scope which makes it difficult to use.
In a Slack conversation with Micha he said,
when you create a new thread and you wanna run CFML code in that thread, you need to create a PageContext for that thread and register that PageContext with that thread and you also need to register the ConfigWeb object with that thread.
I don’t know what it takes “register” a package context or a configWeb object with a thread, so I’m creating this post here so he can hopefully explain that and the answer will be documented for others.