Hello!
I’m trying to improve loading time by using cfthread.
Starting with an Adobe example I produced following piece of code:
<cftimer label="Debug" type="outline">
<cfloop index="pageIndex" from="1" to="10">
<cfthread name="thr#pageIndex#" threadIndex="#pageIndex#" action="run">
<cfset Variables.sThreadOutput[threadIndex]="">
<cfoutput>
<cfsavecontent variable="Variables.sThreadOutput[threadIndex]">#Variables.sThreadOutput[threadIndex]#
Thread index attribute: #threadIndex# Page index value: #pageIndex#
</cfsavecontent>
</cfoutput>
</cfthread>
</cfloop>
<cfthread action="join" name="thr1,thr2,thr3,thr4,thr5,thr6,thr7,thr8,thr9,thr10" timeout="3000"/>
<cfloop index="j" from="1" to="10">
<cfoutput>#Variables.sThreadOutput[j]# <br /></cfoutput>
<cfset threadname="thr"&j>
</cfloop>
</cftimer>
I somehow expected that the pageIndex and threadIndex values would be the same in the gereated output. Somehow they are not. Maybe someone can explain to me, why they are different.
Sometimes I get exceptions when loading the file for the first time. Why does this happen?
Lucee 5.2.9.31 Error (expression)
Message key [1] doesn’t exist
Stacktrace The Error Occurred in
cfthread.cfm: line 18
16:
17: <cfloop index=“j” from=“1” to=“10”>
18: <cfoutput>#Variables.sThreadOutput[j]# <br /></cfoutput>
19: <cfset threadname=“thr”&j>
20: </cfloop>
Java Stacktrace lucee.runtime.exp.ExpressionException: key [1] doesn’t exist
at lucee.runtime.type.util.StructSupport.invalidKey(StructSupport.java:69)
at lucee.runtime.type.StructImpl.get(StructImpl.java:135)
at lucee.runtime.type.util.StructSupport.get(StructSupport.java:244)
at lucee.runtime.util.VariableUtilImpl.get(VariableUtilImpl.java:263)
at lucee.runtime.PageContextImpl.get(PageContextImpl.java:1516)
at marketing.skriptkiste.cfthread_cfm$cf.call(/marketing/skriptkiste/cfthread.cfm:18)
Is there a smarter way to get the generated output from cfthread. I have problems addressing the “OUTPUT” variable within the cfthread-struct.
Slighly off-topic: Neither cffiddle nor trycf can run the sourcecode above. Are there known limitations on that platforms?
Thanks & regards
Michael