Skip to main content
Inspiring
January 16, 2012
Answered

No output when using CFTHREAD for parallel queries

  • January 16, 2012
  • 1 reply
  • 1167 views

Hi,

I want to execute some queries at the same time using cfthread.

But when I join the threads and try to output the query results I get following error:

"The value of the attribute query, which is currently q_emp, is invalid."

Here is my sample code:

<cfthread name="t1" >  

   <cfquery name="q_emp" datasource="test" >

    SELECT empno,ename

    FROM emp

</cfquery>

</cfthread>

<cfthread name="t2" >

<cfquery name="q_dept" datasource="test">

    SELECT deptno, name

    FROM dept

</cfquery>

</cfthread> 

<cfthread  action="join"  name="t1,t2" />

<cfoutput>

<cfloop query="q_emp">

#empno# #ename# </br>

</cfloop>

<cfloop query="q_dept">

#deptno# #name#</br>

</cfloop>

</cfoutput>

What's wrong in my code?

I'm using ColdFusion 9 Standard Edition and Oracle 11g.

regards Claudia

    This topic has been closed for replies.
    Correct answer BKBK

    I suspect the variables q_emp and q_dept can only be accessed in their respective thread-local scopes. That is, within the respective cfthread tags in which they are defined.

    I would redefine q_emp and q_dept in the thread scope, to extend their context to the entire page, as follows:

    <cfthread name="t1" >  

       <cfquery name="q_emp" datasource="test" >

        SELECT empno,ename

        FROM emp

       </cfquery>

      <cfset thread.q_emp = q_emp>

    </cfthread>

    cfthread name="t2" >

    <cfquery name="q_dept" datasource="test">

        SELECT deptno, name

        FROM dept

    </cfquery>

    <cfset thread.q_dept = q_dept>

    </cfthread> 

    cfthread  action="join"  name="t1,t2" />

    cfoutput>

    <cfloop query="t1.q_emp">

    #empno# #ename# </br>

    </cfloop>

    cfloop query="t2.q_dept">

    #deptno# #name#</br>

    </cfloop>

    </cfoutput>

    1 reply

    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    January 16, 2012

    I suspect the variables q_emp and q_dept can only be accessed in their respective thread-local scopes. That is, within the respective cfthread tags in which they are defined.

    I would redefine q_emp and q_dept in the thread scope, to extend their context to the entire page, as follows:

    <cfthread name="t1" >  

       <cfquery name="q_emp" datasource="test" >

        SELECT empno,ename

        FROM emp

       </cfquery>

      <cfset thread.q_emp = q_emp>

    </cfthread>

    cfthread name="t2" >

    <cfquery name="q_dept" datasource="test">

        SELECT deptno, name

        FROM dept

    </cfquery>

    <cfset thread.q_dept = q_dept>

    </cfthread> 

    cfthread  action="join"  name="t1,t2" />

    cfoutput>

    <cfloop query="t1.q_emp">

    #empno# #ename# </br>

    </cfloop>

    cfloop query="t2.q_dept">

    #deptno# #name#</br>

    </cfloop>

    </cfoutput>