Domanda

Grazie per aver risposto !!Ma non sono ancora in grado di farlo.Errore che sto ricevendo è "Elemento Objget1 non è definitivo in un oggetto Java di tipo classe ColdFusion.Runtime.Variablescope."

Di seguito è il mio codice completo.Voglio solo scaricare il valore di ogni filo contenente informazioni CFHTTP.

. http://www.google.com/search? "&" q= Vin + Diesel "&" & num= 10 "&" & start=") />

<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>
.

e quando uso dopo il thread che si unisce all'interno del loop.Ottengo i risultati desiderati Grazie !!

È stato utile?

Soluzione

Due problemi che accadono qui.

Come sottolineato da Zugwalt, è necessario passare esplicitamente in variabili che si desidera fare riferimento all'interno della portata del thread.Ha perso la variabile CGI, quella portata non esiste nel tuo thread.Quindi passiamo solo ciò che dobbiamo usare nel thread, usagent, strbaseurl e intget.

Secondo problema, una volta uniti, i tuoi thread non sono in ambito variabile, sono nell'ambito del cfthread, quindi dobbiamo leggerli da lì.

Codice corretto:

<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>
.

Altri suggerimenti

Generalmente, le variabili non cestroped vengono inserite nell'ambito del Variables, in modo da poter utilizzare la notazione della staffa di struttura per riferirsi a loro:

Variables['objGet#intGet#']
.

o

Variables['objGet'&intGet]
.

Questi sono entrambi fondamentalmente facendo la stessa cosa - solo sintassi diverse.

Code Esegui all'interno di un tag cfthread ha il proprio ambito.Prova a passare la variabile che vuoi accedere come attributo.Mi piace nominarlo qualcosa di diverso solo per aiutarmi a tenere traccia.

<!--- 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>
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top