Anyone out there experienced cfthread users, speci...
# cfml-general
s
Anyone out there experienced cfthread users, specifically cfthread["thread_name"] to get a thread status from outside a thread. A couple Adobe examples show this but I receive an "Element CFNSL_CF_EV_C52447D2_FC48_99DE_D34DCB8424F8C7E4 is undefined in a Java object of type class coldfusion.runtime.LocalScope." (At least I thought I found this type of usage from Adobe examples, but now I am having difficulty finding them again.) I know the thread is still running as I have it logging messages. Maybe cfthread, as in the array reference, was renamed in a later CF version? I'll try to create a "simple" example if I don't get any feedback.
✅ 1
j
Only the request that creates the thread will be able to see the thread in the
cfthread
scope. Something like the following should work.
Copy code
thread name="thread_one" {
    Sleep(5000);
}

// Wait for the thread to finish
ThreadJoin("thread_one");

if (cfthread["thread_one"].status EQ "completed") {
    // The thread finished without error
}
s
Ok, strange. I found the cfthread["threadname"] appears to only be available on the request that started the thread. I saved a copy of this immediately after the cfthread action="run" call and it appears to be working. Hopefully I am explaining this understandably.
LOL. The same thing I found.
My case was across requests. More like:
j
👍 You're off to the races then. Something else to keep in mind when you're working with threads: if the thread will be accessing a persistent scope such as request, variables, session, etc., you could run into race conditions where information is changing, or possibly will no longer exist. If you need to make sure the information is always available to the thread, you can pass the value in when you are spawning the thread.
s
Yep. I have a "protectedData" variable that is only accessed within lock blocks. I think this was my last hurdle. I have a CF native simple logging component that does not require third-party libraries. I've been having a lot of jar wars with various CF and Lucee versions and common logging between them all.