Here try this.  I snipped it out of something I use to build static pages
with CFHTTP.  It builds thousands of them based on query output.  I wanted
it to run multiple threads at once but not so many it fried CF.  So the
code keeps track of how many threads are running and limits their number to
a value you specify.  variables.threadcount sets the number of threads to
allow to run concurrently.  For your routine you could have the urls you
want to canvas in a db, query them as seen below and then reference the
query output's current row in the loop via the loopCounter variable as
shown.

<cfscript>
variables.threadArray=arrayNew(1);
variables.threadCount=3;
</cfscript>
<cfquery
    name="getData"
    datasource="#server.DSN#"
    username="#server.userName#"
    password="#server.password#">
    SELECT
        fileName.primaryKey

    FROM
        fileName
    WHERE
        0=0
    ORDER BY
        fileName.primaryKey ASC
</cfquery>
<cfset variables.loopCounter=0>
<cfloop
    condition="variables.loopCounter LT getData.recordCount">
    <!---
    count the threads that are currently live
    --->
    <cfset variables.threadsLive=arrayLen(variables.threadArray)>
    <!---
    Do we have an available thread?
    --->
    <cfif variables.threadsLive lt variables.threadCount>
        <!---
        A thread is available.  Increment the loopCounter and give it a name
        --->
        <cfset variables.loopCounter=variables.loopCounter+1>
        <cfset variables.thisThreadID=createUUID()>
        <cfset
temp=arrayAppend(variables.threadArray,variables.thisThreadID)>
        <!---
        create the thread whose name we specified and have reserved
        --->
        <cfthread
            name="#variables.thisThreadID#"
            action="run">
            <!---
            CF Code to be run inside the thread goes here.
            This next cfset is just a dummy
            --->
            <cfset variables.foo=getdata.ID[variables.loopCounter]>
            <!---
            remove the now-completed thread from the "live" list
            --->
            <cfset
temp=arrayDeleteAt(variables.threadArray,arrayFindNoCase(variables.threadArray,variables.thisThreadID))>
        </cfthread>
    </cfif>
</cfloop>


-- 
--m@Robertson--
Janitor, The Robertson Team
mysecretbase.com


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:360142
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to