5

返信ありがとうございます!! しかし、私はまだそれをすることができません。私が得ているエラーは、「要素objGet1は、タイプクラスcoldfusion.runtime.VariableScopeのJavaオブジェクトで定義されていません。」です。

以下は私の完全なコードです。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>

ループ内でスレッドを結合した後に使用する場合。希望の結果が得られましたありがとうございます!!

4

3 に答える 3

6

ここで起こっている2つの問題。

Zugwaltが指摘しているように、スレッドのスコープ内で参照する変数を明示的に渡す必要があります。彼はCGI変数を見逃しました、そのスコープはあなたのスレッド内に存在しません。したがって、スレッド、userAgent、strBaseURL、およびintGetで使用する必要があるものだけを渡します。

2番目の問題は、一度結合すると、スレッドは可変スコープになく、cfthreadスコープにあるため、そこから読み取る必要があります。

修正されたコード:

<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>
于 2010-07-15T18:38:29.703 に答える
3

通常、スコープ外の変数はスコープに入れられるVariablesため、構造体ブラケット表記を使用してそれらを参照できます。

Variables['objGet#intGet#']

また

Variables['objGet'&intGet]

これらは両方とも基本的に同じことをしています-ただ異なる構文です。

于 2010-07-14T17:11:32.790 に答える
0

cfthreadタグ内で実行されるコードには、独自のスコープがあります。アクセスしたい変数を属性として渡してみてください。追跡しやすくするために、別の名前を付けるのが好きです。

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

于 2010-07-15T18:01:00.830 に答える