Copy link to clipboard
Copied
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.
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">
<cfse
...Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
I included other threads and i see the difference on the time.
Nice feature of CF !!!
Best,