Provide mechanism for loading context inside a "non-CF" thread.

Description

A big pain of using java libraries or even JDK packages that handle their own threading, is the difficulty of loading the correct fusion/page context into those threads. This is very common in all the concurrent libs, java streams, and any Java SDK providing a consumer pattern. Ortus has manually worked around this for years now in our own libraries, but the code has been fragile and given us no end of issues. The CFML engines really need to address this properly. This feature would also provide some very interesting options for REPL functionality on a running server.

What we need is the ability to ask Lucee to load any of the following in a thread that wasn’t created by an HTTP request, CFThread, or runAsync().

  • associate current thread with a given application -- provide application name

  • associate current thread with given session -- provide session ID and application name

  • associate current thread with given request -- provide page context object from original request (Would have caveats if original request was finished-- may need pc.clone() option.)

There are many different use cases for this, thus the three options above. Sometimes I just want a consumer thread to run in the context of my application. Other times, I may need it to run in the context of a given user, or even in the context of a specific HTTP request (such as processing parallel java streams)

To avoid the issues of the user needing to explicitly cleanup the thread’s context, I propose encapsulating the invocation via a closure as follows.

Run in an application context (keeps application scope):

runThreadInContext( application="myApp", udf=()=>{ // run My logic inside some random thread } );

Run in a session/application context (keeps session scope for user). Need to figure out how to support both CFID/CFToken and JSessionID easily. My suggestion would be to implement sessionGetMetadata() from Adobe but add in the session keys and then just accept that entire struct and figure out what keys are present. This would provide an easy way to both capture and provide the session metadata.

runThreadInContext( application="myApp", sessionMetadata=mySessMeta, udf=()=>{ // run My logic inside some random thread } );

Run in a request context (keeps url, form, cgi, request scopes):

runThreadInContext( pageContext=myContext, udf=()=>{ // run My logic inside some random thread } );

Activity

Brad Wood 
22 April 2022 at 19:17

Details

Assignee

Reporter

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Priority

Created 22 April 2022 at 19:08
Updated 3 May 2022 at 16:13