Hi,
I’m testing cfthread since few days now in order to develop a specifc
backend feature.
I know about ACF9 behaviour and that’s why this led me to this recently
: Redirecting to Google Groups
Today I’ve encounter a kind of problem/bug with Lucee’s cfthread (Lucee
4.5.1.015 / JDK7, Tomcat8 / Linux).
I would describe the bug as follow :
- Sometimes onRequestEnd() is finished before all child threads are
created/started. - Maybe this happens randomly but when it is the case then a given child
thread will fail to join with others. - i.e The child thread
getPageContext().getParentPageContext().getThreadScopeNames() will
return an empty array.
One possible explanation could be that thread creation/start is deferred
from the application listener execution.
One workaround in the meantime is to make the current request wait for all
thread creation/start before onRequestEnd().
If someone could confirm this issue and/or raise a ticket I would really
appreciate (In fact I could but long and hard to explain why I don’t).
Also you may not be able to easily reproduce the bug (may or may not)
because this may seem to happen randomly while it doesn’t.
In my case I couldn’t reproduce the bug when I refreshed the same page. But
I could when I open the same page in a new browser page (i.e instead of
refreshing).
This is a snippet which could help to understand the issue (the “var”
keywords came from a function of mine…) :
// A basic thread
cfthread(name="T1",action="run") {
writeLog("=== T1 starts ===");
// Does a lot of thing here which last more than a second
};
// Another thread which wants to join with the first above
cfthread(name="T1-monitor",action="run") {
writeLog("=== T1 monitor starts ===");
try {
threadJoin("T1",someTimeouValue);
// Does a lot of thing here which last more than a second
} catch(any error) {
// An exception is catched here when the bug occurs
// It mainly says that there's no thread named "T1" and that there's no other threads eithers in the page context
}
};
/* Say in Application.onRequestStart() there's a log like "Executing onRequestStart()"
And in Application.onRequestEnd() there's a log like "Executing onRequestEnd()".
So when the bug occurs, then you get the following log output :
-> "Executing onRequestStart()"
-> "Executing onRequestEnd()"
-> "=== T1 starts ==="
-> "=== T1 monitor starts ==="
And when the bug DOES NOT occurs, then you get the following log output :
-> "Executing onRequestStart()"
-> "=== T1 starts ==="
-> "=== T1 monitor starts ==="
-> "Executing onRequestEnd()"
*/</cfscript>
One can test the result of one of : structKeyList(cfthread),
getPageContext().getThreadScopeNames(), etc…
PS : Also if someone could advice a good online copy/paste cfml syntax
highlighter that works with google groups…