I need to run certain blocks of ColdFusion code in a regular user session (for example: the user clicks print and I create the PDF). This web page is interactive and the user immediately receives a PDF file.
But I also need to run the same exact block of code many times in a loop (more than 1000 iterations). To do this, we will inform the user that an email will be sent to them when sent. I create <cfthread>with low priority and create the same code. The problem is that the executable code is heavily dependent on the variables in the session area. Therefore, if the user crashes, the error flows and dies when he enters the var session. As for the code in question, I know that I can change the variables so as not to use the session area, then the stream will not be a problem, but we will not be able to change this code. So, I tried to hack many years ago, which worked, I never felt good, and I was wondering if anyone could think of a better approach. This is the hack ...
<cfapplication name="backgroundThread" sessionTimeout="#CreateTimeSpan(0, 0, 600, 0)#" sessionManagement="Yes">
<cflock scope="session" timeout="30" type="Exclusive">
<cfloop collection="#this.session#" item="session_element">
<cfset new_session_element = evaluate("this.session." & "#session_element#")>
<cfset "session.#session_element#" = new_session_element>
</cfloop>
</cflock>
<cfthread action="run" priority="low" name="#this.threadid#" session=session>
, /, /. , , , , , .
. , . . <cfapplication>?
application.cfc->onSessionStart, , Adobe: , ColdFusion . , , .
24 2014 : , ( CF10)...
<cfthread action="run" name="testingSession" session="#session#" priority="LOW">
<cfset form.session = session>
<cftry>
<cfloop from="1" to="200" index="i">
<cfscript>sleep(3000);</cfscript>
<cfquery name="q1" datasource="#session.sv.ds#">
select sysdate thedate from dual
</cfquery>
<cflog file="threadTest6" text="thread running... #i# ... #q1.thedate#">
</cfloop>
<cfcatch type="any">
<cflog file="threadTest6" text="error: #cfcatch.detail# /// #cfcatch.message#">
</cfcatch>
</cftry>
</cfthread>
, "". ...
<cfset StructDelete(Session, 'dev')>
<cfset StructDelete(Session, 'sv')>
<cfset StructDelete(Session, 'act')>
<cfset StructClear(Session)>
, , , , , . , . threadTest6.log...
"Severity","ThreadID","Date","Time","Application","Message"
"Information","cfthread-1","02/24/14","16:26:04",,"C:\ColdFusion10\cfusion\logs\threadTest6.log initialized"
"Information","cfthread-1","02/24/14","16:26:04","CMPRO","thread running... 1 ... 2014-02-24 16:26:04.0"
"Information","cfthread-1","02/24/14","16:26:07","CMPRO","thread running... 2 ... 2014-02-24 16:26:07.0"
"Information","cfthread-1","02/24/14","16:26:10","CMPRO","thread running... 3 ... 2014-02-24 16:26:10.0"
"Information","cfthread-1","02/24/14","16:26:13","CMPRO","thread running... 4 ... 2014-02-24 16:26:13.0"
"Information","cfthread-1","02/24/14","16:26:16","CMPRO","thread running... 5 ... 2014-02-24 16:26:16.0"
"Information","cfthread-1","02/24/14","16:26:19","CMPRO","thread running... 6 ... 2014-02-24 16:26:19.0"
"Information","cfthread-1","02/24/14","16:26:22","CMPRO","error: The value of the attribute datasource, which is currently '', is invalid. /// Attribute validation error for tag CFQUERY."