How can I access a dynamic thread name in ColdFusion? Normally if I'm using a dynamic variable name, I'd do something like this:
<cfloop from="1" to="10" index="counter" >
<cfset Names[counter] = rereplace( createUUID(), "[-_\.]", "", "all") />
<cfset something[ Names[counter] ] = 1 />
</cfloop>
<cfoutput>
#( something[ Names[1] ] + something[ Names[2] ] + something[ Names[3] ] )#
</cfoutput>
However, trying to do this with threads seems trickier, as I can't find a way to instantiate them besides using <cfthread>, which doesn't want to allow me to create a thread as a struct member. Here's what I've tried:
Attempt 1
<cfloop from="1" to="10" index="counter" >
<cfset ThreadNames[counter] = rereplace( createUUID(), "[-_\.]", "", "all") />
<cfthread action="run" name="#something[ ThreadNames[counter] ]#" >
<cfset Thread.something = 1 />
</cfthread>
</cfloop>
Element ... is undefined in a CFML structure referenced as part of an expression.
This one gets as far as the output before throwing an error. I didn't really expect the thread to be in the variables scope, but I can't specify the scope and I also can't find what scope it's built into. In short, I can't figure out how to access the thread from there:
Attempt 2
<cfloop from="1" to="10" index="counter" >
<cfset ThreadNames[counter] = rereplace( createUUID(), "[-_\.]", "", "all") />
<cfthread action="run" name="#ThreadNames[counter]#" >
<cfset Thread.something = 1 />
</cfthread>
</cfloop>
<cfthread action="join" name="#ThreadNames[1]#, #ThreadNames[2]#, #ThreadNames[3]#" />
<cfoutput>
#( VARIABLES[ThreadNames[1]].something + VARIABLES[ThreadNames[2]].something + VARIABLES[ThreadNames[3]].something )#
</cfoutput>
Element ... is undefined in a Java object of type class coldfusion.runtime.VariableScope.
Non-dynamic Example
For reference, here's how the code looks before trying to throw in the uuids
<cfloop from="1" to="10" index="counter" >
<cfthread action="run" name="thread#counter#" >
<cfset Thread.something = 1 />
</cfthread>
</cfloop>
<cfthread action="join" name="thread1, thread2, thread3" />
<cfoutput>
#( thread1.something + thread2.something + thread3.something )#
</cfoutput>