coldfusion - Can I queue a cfthread with the same name in a multi user environment? -
user fires off cfthread called 'thread1'. thread takes 30 minutes complete, , 'set & forget' thread. in other words, thread not join main page request. thread contains routines highly memory intensive.
user b fires off same named thread [cfthread name 'thread1'], different page request, 5 minutes after user a.
in scenario, how can queue threads, can reduce processing load on cf application server?
please note, understand thread queuing threads have different names. talking instances of same thread.
the answer lock function call inside cfthread tag. here example:
<cfthread action="run" name="thread1"> <cflock name="threadlock" type="exclusive" timeout="10000"> <cfset calltosomefunction()> </cflock> </cfthread>
so, test this, copy code below, .cfm template. open firefox, , open chrome. test template inside firefox. wait 5 seconds , test template inside chrome:
<cfthread action="run" name="thread1"> <cfset tickstart = gettickcount()> <cfset time = structnew()> <cfset time.timestart = dateformat(now(),'dd-mm-yy') & " " & timeformat(now(),'hh-mm-ss')> <cflock name="threadlock" type="exclusive" timeout="10000"> <cfthread action="sleep" duration="#(10 * 1000)#" /> </cflock> <cfset tickend = gettickcount()> <cfset tick = tickend - tickstart> <cfset time.tick = tick/1000> <cfset time.timeend = dateformat(now(),'dd-mm-yy') & " " & timeformat(now(),'hh-mm-ss')> <cfdump var="#time#" format="html" metainfo="no" output="somefilepath\#thread1.name#-#dateformat(now(),'dd-mm-yy')#-#timeformat(now(),'hh-mm-ss')#.htm" /> </cfthread>
Comments
Post a Comment