When should you use cfthread?

Could you give a simple scenario in which a thread is needed? Thanks Nich

+3
source share
4 answers

I used it in a situation where we needed to initiate data processing at the back end to tabulate the data before the user executes some reports. Therefore, after logging in to the system, we use cfthread to run the task in order to create storage data for the user. It works great!

So, think of cfthread as a way to perform an asynchronous task on demand. Very useful in the right situation!

+4
source

cfthread, .

: , , , , . cfthread . :

<cfdirectory directory="x" action="read" name="allFiles" />

<cfloop query="allFiles">
  <cfthread action="run" name="thread-#allFiles.name#>
    <!--- Read your file in and do processing --->
  </cfthread>
</cfloop>

, CF Admin , ! .

, . Google. Ben Nadal cfthread primer .

: - ! .

cfthread - ColdFusion, !

+3

cfthread .

, , , . , RSS- . RSS , . , .. RSS. RSS.

The second way I used is an alternative to using the on-demand scheduler. We created complex PDF documents. The person who generated them did not need them immediately, so instead of getting the user stuck while creating the document, we created an unrelated stream for processing PDF. Then we limited the number of cfthreads processed at any ppoint. Now, regardless of load, cfthreads will simply queue and process as resources become available.

+3
source
<!--- store value into message varaible --->
<cfset variables.message = "It orginal value.">

<!--- create new thread --->
<cfthread name="ThreadOne">
<!--- overwrite new value into existing variable. --->
<cfset variables.message = "It comes from thread.">
</cfthread>

<!--- join thread --->
<!---
If we leave this join, the code within thread will execute but won't display the value.
--->
<cfthread action="join" name="ThreadOne" />

<!--- Output --->
<cfoutput>#variables.message#</cfoutput>

Check the encoding above. This is clear.

-1
source

Source: https://habr.com/ru/post/1784876/


All Articles