tags:

views:

47

answers:

3

Thanks for replying!! But I am still not able to do it. Error that I am getting is "Element objGet1 is undefined in a Java object of type class coldfusion.runtime.VariableScope."

Below is my full code. I just want to dump the value of each thread containing cfhttp information.

<cfset intStartTime = GetTickCount() />

<cfloop index="intGet" from="1" to="10" step="1">

    <!--- Start a new thread for this CFHttp call. --->
    <cfthread action="run" name="objGet#intGet#">

        <cfhttp method="GET" url="#strBaseURL##((intGet - 1) * 10)#" useragent="#CGI.http_user_agent#" result="THREAD.Get#intGet#" />

    </cfthread>

</cfloop>

<cfloop index="intGet" from="1" to="10" step="1">

    <cfthread action="join" name="objGet#intGet#" />
    <cfdump var="#Variables['objGet'&intGet]#"><br />

</cfloop>

and when I use after thread joining inside the loop. I get the desired results Thanks!!

+2  A: 

Generally, unscoped variables get put into the Variables scope, so you can use struct bracket notation to refer to them:

Variables['objGet#intGet#']

or

Variables['objGet'&intGet]

These are both basically doing the same thing - just different syntaxes.

Peter Boughton
still getting error!!
Deepak Yadav
Hmmm, can you confirm that if you put <cfdump var=#objGet1# /> that it does dump that first one?Also, try setting the `name` in `cfthread` to `"variables.objGet#intGet#"` - shouldn't be necessary, but I've not needed to use cfthread yet, so not entirely sure how it behaves.
Peter Boughton
A: 

Code run inside a cfthread tag has its own scope. Try passing the variable you want it to access as an attribute. I like to name it something different just to help me keep track.

<!--- Start a new thread for this CFHttp call. --->
<cfthread action="run" name="objGet#intGet#" intGetForThread="#intGet#">

    <cfhttp method="GET" url="#strBaseURL##((intGetForThread- 1) * 10)#" useragent="#CGI.http_user_agent#" result="THREAD.Get#intGetForThread#" />

</cfthread>

Zugwalt
+2  A: 

Two problems happening here.

As pointed out by Zugwalt, you need to explicitly pass in variables that you want to reference within the scope of your thread. He missed the CGI variable, that scope doesn't exist within your thread. So we pass in just what we need to use in the thread, userAgent, strBaseURL, and intGet.

Second problem, once joined, your threads are not in variable scope, they are in the cfthread scope, so we have to read them from there.

Corrected code:

<cfloop index="intGet" from="1" to="2" step="1">

    <!--- Start a new thread for this CFHttp call. Pass in user Agent, strBaseURL, and intGet --->
    <cfthread action="run" name="objGet#intGet#" userAgent="#cgi.http_user_agent#" intGet="#intGet#" strBaseURL="#strBaseURL#">

        <!--- Store the http request into the thread scope, so it will be visible after joining--->
        <cfhttp method="GET" url="#strBaseURL & ((intGet - 1) * 10)#" userAgent="#userAgent#" result="thread.get#intGet#"  />

    </cfthread>

</cfloop>

<cfloop index="intGet" from="1" to="2" step="1">

    <!--- Join each thread ---> 
    <cfthread action="join" name="objGet#intGet#" />
    <!--- Dump each named thread from the cfthread scope --->
    <cfdump var="#cfthread['objGet#intGet#']#" />

</cfloop>
Anthony
Good catches Anthony! I didn't look closely enough at the entire problem but luckily you really nailed it!
Zugwalt