문제

감사에 대한 회신!!하지만 나는 아직도 할 수 없습니다.오류가 나는 것입 "요소 objGet1 가 정의되지 않 Java 유형의 객체 클래스 coldfusion.런타임입니다.VariableScope."

아래에 나의 전체 코드입니다.나는 그냥하고 싶은 덤프 각각의 가치를 포함하는 스레드 cfhttp 정보입니다.

http://www.google.com/search?" &"q=Vin+디젤 엔진"&"&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>

내가 사용 후에는 스레드에 합류 루프 안에서.내가 원하는 결과를 얻 감사합니다!

도움이 되었습니까?

해결책

여기서 두 가지 문제가 발생합니다.

zugwalt가 지적한 것으로, 스레드의 범위 내에서 참조 할 변수를 명시 적으로 전달해야합니다.그는 CGI 변수를 놓치지 않았으며 그 범위는 스레드 내에 존재하지 않습니다.그래서 우리는 스레드, userAgent, strbaseurl 및 intget에서 사용할 필요가 있습니다.

두 번째 문제가 발생하면 스레드가 가변 범위에 있지 않으므로 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>
.

다른 팁

일반적으로,범위가 지정되지 않은 변수로 얻을 넣 Variables 범위,그래서 당신이 사용할 수 있는 구조체 브래킷 표기를 그들을 참조하십시오:

Variables['objGet#intGet#']

Variables['objGet'&intGet]

이들은 모두 기본적으로 같은 일을하고있다-그냥 다른 구문.

코드 실행 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>
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top