House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

cfthread running condition?

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Is there a way to make the start of one thread
Rick Faircloth
08/28/08 10:11 P
In the docs under timeout it says:
Joey Krabacher
08/29/08 04:25 P
Rick Faircloth wrote:
Ian Skinner
08/29/08 02:13 P
Rick Faircloth wrote:
Ian Skinner
08/29/08 04:24 P
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rick Faircloth
08/28/2008 10:11 PM

Is there a way to make the start of one thread conditional upon the ending of a previous thread? I want to keep only one thread at a time running and would like to set up a series of threads to run, but only one at a time. I've been doing this with scheduled tasks and emailing completion to myself for verification of success each morning, but running 54 schedule task templates currently, with having to add another 30 or so soon has just become quite cumbersome. Didn't know if there were any options. Too bad we can't number the threads to run sequentially and set them to run only individually. Rick

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Chris Blackwell
08/29/2008 07:59 AM

This should be pretty simple to achieve.  One of the restrictions with threads is that a cfthread can not spawn another cfthread.  So your going to need one scheduled task that runs at a suitable interval.  It will need to see if theres a thread running and if not, kick off the first thread.  The threads will need to report there current status somewhere the scheduled task can check - to a db or application scope.  When the scheduled task next runs it checks if the previous task completed and then starts the next thread. Chris ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
joey krabacher
08/29/2008 02:08 PM

You might be able to kick of the first thread (set the action to run) then have a list or something that you can loop over and have a "join" cfthread inside the loop with the same name as the first one. Something like this. <cfthread action='run' name='t1'> do something </cfthread> <cfloop index='i' from='1' to='50'>     <cfthread action='join' name='t1'>         do something     </cfthread> </cfloop> I have not tried this, but the 'join' action tells cf to wait for the named thread(t1) to finish. Joey ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rick Faircloth
08/29/2008 03:57 PM

I checked into using a "join" thread and at first glance it seemed perfect.  But from the description in the docs, it seems to work the opposite of what I'd hoped.  From the docs: "The following code, for example, joins three threads to the current thread (often, the main thread).  The current thread waits up to six seconds for the other threads to complete, and continues processing if one or more threads do not complete by then." <cfthread action="join" name="t1, t2, t3" timeout="6000"/> -------------------------------- From the description, it sounds like a "join" action causes threads that join a running thread to wait until the "joining" threads are complete before it finishes. I must admit, it's a little confusing.  I thought it would work as you described, that the joining threads would wait until the thread they were joining was finished before processing.  But the description makes it sound the other way around. ??? Rick > You might be able to kick of the first thread (set the action to run) then have a list or something that ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Joey Krabacher
08/29/2008 04:25 PM

In the docs under timeout it says: 'The number of milliseconds that the current thread waits for the thread or threads being joined to finish. If any thread does not finish by the specified time, the current thread proceeds. If the attribute value is 0, the following action occurs:     * The current thread continues waiting until all joining threads finish.     * If the current thread is the page thread, the page continues waiting until the threads are joined, even if you specify a page time-out.' This sounds like if you do not set the timeout attribute then the thread just waits until the joining thread finishes. ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rick Faircloth
08/29/2008 06:59 PM

I'm not too sure what constitutes a "page thread". Assuming that it's the processing of the .cfm page, then that wouldn't really apply, I don't think, because I'd be using these merged templates with multiple threads coded in them as part of scheduled tasks, which, if I understand correctly wouldn't involve a "page thread." I'm looking for a way to combine the 54 templates I currently have to process data every day into 4 or 5 templates. I actually tried setting the wait time to 0, and the template threw an error.  When I set a time, it ran fine.  Perhaps I should leave the wait time attribute out entirely.  Perhaps that would default to 0. Also, even with the wait time set to 0, I don't want the "joining" threads to finish first...I want them to finish *after* the first thread that they would be joining. > In the docs under timeout it says: > 'The number of milliseconds that the current thread waits for the thread or threads being joined to > finish. If any thread does not finish by the specified time, the current thread proceeds. > > If the attribute value is 0, the following action occurs: > >     * The current thread continues waiting until all joining threads finish. >     * If the current thread is the page thread, the page continues waiting until the threads are joined, > even if you specify a page time-out.' > > This sounds like if you do not set the timeout attribute then the thread just waits until the joining > thread finishes. >

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ian Skinner
08/29/2008 02:13 PM

Rick Faircloth wrote: > Is there a way to make the start of one thread > conditional upon the ending of a previous thread? It should be possible using the thread.status feature.  You would create a thread then watch the status until it reports "completed" then start the next thread. Don't have a code example, but that is what I would imagine from my reading and experimenting with threads a while back.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rick Faircloth
08/29/2008 04:02 PM

I started another thread with a question about some code in the docs that used a sleep function and a status check to delay a thread's start, but the code in the waiting thread was in <cfscript> blocks and the processing was supposed to occur in the block.  I haven't used cfscript so I asked if it was possible to just have the block run and then let the rest of the thread use regular CFML, but my data didn't get processed by that particular thread, but the data was processed by all other threads in the .cfm. Here's the question as I posted it: I'm trying to set up a way to check the status of threads and implement a sleep function that loops and delays a following thread's initialization until the status of the first thread is "Completed". I found an example in the CF8 docs using a sleep timer this is placed just inside the opening <cfthread...> tag of the cfthread that needs to wait.     <cfscript>         thread.sleepTimes=0;         thread.initialized=false;         while ((2_hmls_offices.Status != "COMPLETED") && (2_hmls_offices.Status                 != "TERMINATED")) {             sleep(2000);             thread.sleeptimes++;         }         // Only do the post-initilization code if 2_hmls_offices is complete.         If (threadA.Status == "COMPLETED") {             thread.initialized=true;             // Post-initialization code would go here.         }     </cfscript> I understand what's happening inside the cfscript, but I'd like to continue the processing *outside* the cfscript tag and use regular CFML, not cfscript for the thread. This example states, in the last line "//Post-initialization code would go here". Can I just use the cfscript as is and follow the cfscript block with my cfqueries, etc., or would all my thread processing have to occur within the cfscript block?  Is there a way to break out of the cfscript block once the status of the first thread, "2_hmls_offices", is "Completed" and go on to process regular CFML code? Thanks, Rick ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ian Skinner
08/29/2008 04:24 PM

Rick Faircloth wrote: > Is there a way to break out of the cfscript block once > the status of the first thread, "2_hmls_offices", is "Completed" and go > on to process regular CFML code? There is nothing special about the <cfscript>...</cfscript> code.   This is not a requirment of threads or anything, just a personal preference for coding style.  The entire example could easily be rewritten using tag syntax. <cfset thread.seepTimes = 0> <cfset thread.initalized = false> <cfloop condition="2_hmls_offices>status NEQ 'COMPLTETED' AND 2_htmls_offices.Status NEQ 'TERMINATED'">   <cfset sleep(2000)>   <cfset thread.sleeptimes++> </cfloop> .... Not syntax checked to make sure I translated that 100% correctly but you should get the idea.

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dave Watts
08/29/2008 07:09 PM

> I'm not too sure what constitutes a "page thread". > > Assuming that it's the processing of the .cfm page, then that > wouldn't really apply, I don't think, because I'd be using > these merged templates with multiple threads coded in them as > part of scheduled tasks, which, if I understand correctly > wouldn't involve a "page thread." The main thread is the one directly responding to the HTTP request. Scheduled tasks are HTTP requests. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ Fig Leaf Software provides the highest caliber vendor-authorized instruction at our training centers in Washington DC, Atlanta, Chicago, Baltimore, Northern Virginia, or on-site at your location. Visit http://training.figleaf.com/ for more information!

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rick Faircloth
08/29/2008 09:40 PM

But unlike a "page thread" that's running in a browser, the "scheduled task page thread" isn't subject to a timeout, right? ----- Excess quoted text cut - see Original Post for more -----

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dave Watts
08/29/2008 10:31 PM

> But unlike a "page thread" that's running in a browser, > the "scheduled task page thread" isn't subject to a > timeout, right? Why wouldn't it be? It's just another HTTP request. Dave Watts, CTO, Fig Leaf Software

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Mark Mandel
08/30/2008 12:48 AM

Silly question - why not just run the executing code you want to fire to happen at the end of thread 1? It has exactly the same result, there is no need to create a whole new thread, as you can just continue in the one you are in. Mark ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
James Holmes
08/30/2008 02:37 AM

Yeah, I've been wondering why this would use multiple threads when the aim is to deliberately single thread the execution. > Silly question - why not just run the executing code you want to fire > to happen at the end of thread 1? It has exactly the same result, > there is no need to create a whole new thread, as you can just > continue in the one you are in. -- mxAjax / CFAjax docs and other useful articles: http://www.bifrost.com.au/blog/

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rick Faircloth
08/30/2008 08:32 AM

What!  Are you saying the Emperor has no clothes!  :o) Why point out the obvious and ruin a perfectly good, pointless discussion! It very well may be time to go back to just consolidate more and more code into one or at least few threads. I think I got started on the separate threads way back when I was first testing parts of the functionality in a browser and wanted feedback through the browser output about how the processing was working. Then I moved that code into separate templates that had to run in a specific order to process all the data. (54 templates at this point) I think I've just become obsessed with making threads bend to my will. It's definitely been a good learning experience about cfthread. I'll have to sit back and reconsider how best to use cfthread now that I'm consolidating many similar functions into single templates and running them as scheduled tasks still. I wish there was a way to watch scheduled tasks at work...showing data processing, outputting results, starting and finishing of tasks, etc. I generally just run the tasks in a browser when I need to see feedback. Or I send myself an email with results I need to see. Am I missing some sort of obvious feedback method when scheduled tasks (and cfthread's, for that matter) are run? Rick ----- Excess quoted text cut - see Original Post for more -----


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

February 12, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29