Skip to main content
Inspiring
June 12, 2013
Answered

Cfthread question

  • June 12, 2013
  • 1 reply
  • 617 views

Hi All,

My first try using cfthread. I want two calculations to run at the same time:

<cffunction name="getData" output="false" access="remote">

<cfargument name="req_id" type="numeric" required="yes" />

<cfset var returnArray = ArrayNew(1)>

<cfthread name="processQuery" action="run">

     <cfset myObj = CreateObject("component", "myComponent") />

     <cfset returnArray [1] = myObj.getCalculationA(arguments.my_id) />

     <cfset returnArray [2] = myObj.getCalculationB(arguments.my_id) />

</cfthread>

<cfthread name="processQuery" action="join" />

<cfreturn returnArray />

</cffunction>

It is not returning anything. What am i missing?

Thanks in advance.

    This topic has been closed for replies.
    Correct answer jfb00

    Couple issues with variables scope, but the time of the function still the same.

    Do i need to setup something in the cf administrator?

    I am using cf 9 enterprise.

    Here is my new code:

    <cffunction name="getData" output="false" access="remote">

    <cfargument name="my_id" type="numeric" required="yes" />

    <cfset variables.my_id = arguments.my_id />

    <cfset variables.returnArray = ArrayNew(1) />

    <cfset variables.myObj = CreateObject("component", "myComponent") />

    <cfthread name="processA" action="run">

         <cfset variables.returnArray [1] = variables.myObj.getCalculationA(variables.my_id) />

    </cfthread>

    <cfthread name="processB" action="run">

             <cfset variables.returnArray [2] = variables.myObj.getCalculationB(variables.my_id) />

    </cfthread>

    <cfthread name="processA, processB" action="join" />

    <cfreturn variables.returnArray />

    </cffunction>

    1 reply

    jfb00AuthorCorrect answer
    Inspiring
    June 12, 2013

    Couple issues with variables scope, but the time of the function still the same.

    Do i need to setup something in the cf administrator?

    I am using cf 9 enterprise.

    Here is my new code:

    <cffunction name="getData" output="false" access="remote">

    <cfargument name="my_id" type="numeric" required="yes" />

    <cfset variables.my_id = arguments.my_id />

    <cfset variables.returnArray = ArrayNew(1) />

    <cfset variables.myObj = CreateObject("component", "myComponent") />

    <cfthread name="processA" action="run">

         <cfset variables.returnArray [1] = variables.myObj.getCalculationA(variables.my_id) />

    </cfthread>

    <cfthread name="processB" action="run">

             <cfset variables.returnArray [2] = variables.myObj.getCalculationB(variables.my_id) />

    </cfthread>

    <cfthread name="processA, processB" action="join" />

    <cfreturn variables.returnArray />

    </cffunction>

    jfb00Author
    Inspiring
    June 12, 2013

    I included other threads and i see the difference on the time.

    Nice feature of CF !!!

    Best,