Well I fail.

Can anybody point out what is fundamentally wrong with this code.  Such 
that it has at least a 50% chance of complete failure resulting in a 
non-responsive ColdFusion server that must be restarted.  What gets me 
is that sometimes it works completely correct and produces all the 
desired files.  The next time, with the exact same code and data, it 
fails and hangs the server, but generates no exceptions or errors.  At 
least none that I have been able to find.

<cfsetting requesttimeout="1800">
<cfinclude template = "scripts.cfm">
<cfset Application.DSN = LIC_DSN>

<h1>PROCESSING</h1>

<cfset variables.pathDate = #dateFormat(now(),'yyyy')#/>
<cfset variables.pIssueDate = #dateFormat(now(),'mm/dd/yy')#>

<!--- GET RENEWAL ID --->
<cfstoredproc procedure="REPORT_UTILS.getBatchRenewals"
  dataSource = "#LIC_DSN#">
  <cfprocresult name = "variables.ResultFirms">
</cfstoredproc>

<cfset variables.threads = "">
<ul>
<cfloop index = "i" from="1" to="#ResultFirms.recordcount#">
    <cfif i GT 10><cfbreak></cfif><!--- Development throttle ... only 
process first 15 rows --->
    <cfset variables.threads = 
listAppend(variables.threads,'batchRenew_thread#i#')>
    <li><cfoutput>batchRenew_thread#i#</cfoutput></li>
   
    <cfthread name="batchRenew_thread#i#" threadIndex="#i#" 
threadPathDate="#pathDate#" action="run">
    <cfset var vRenewalReport = "">

    <cftry>
       
        <!--- GET RENEWAL ID --->
        <cfstoredproc procedure="REPORT_UTILS.getRenewalSequenceId"
            dataSource = "#LIC_DSN#">
            <cfprocparam type="out" variable="thread.vRenewalSeq" 
CFSQLType="CF_SQL_VARCHAR">
        </cfstoredproc>
       
        <!--- PATH ---> 
        <cfset thread.vOutputFilePath = variables.RENEWALS_FILE_PATH &
               variables.pathDate & "\" &
                     Trim(variables.ResultFirms["firmno"][threadIndex]) 
& "\"/>
               
        <!--- CREATE OUTPUT PATH --->
        <cfif DirectoryExists(thread.vOutputFilePath) is False>
            <cfdirectory action="create" 
directory="#thread.vOutputFilePath#"/>
        </cfif>
         
        <!--- FILE NAME --->
        <cfset thread.vOutputFilePath &= GetFileName()/>
       
        <!--- BUILD REPORT --->
        <cfreport template="ren.cfr" format="pdf" 
name="vRenewalReport">     
            <cfreportparam name="pFirmNo" 
value="#variables.ResultFirms['firmno'][threadIndex]#">
            <cfreportparam name="pIssueDate" 
value="#DateFormat(variables.pIssueDate, 'mm/dd/yy')#">
            <cfreportparam name="pRenewalId" value="#thread.vRenewalSeq#">
        </cfreport>
       
        <cfpdf action="write" source="vRenewalReport" 
destination="#thread.vOutputFilePath#" overwrite="yes">
       
        <cfset vRenewalReport = "">
       
        <!--- INSERT RENEWAL --->
        <cfstoredproc procedure="REPORT_UTILS.insertRenewal"
            dataSource = "#LIC_DSN#">
            <cfprocparam type="in" value="#thread.vRenewalSeq#" 
CFSQLType="CF_SQL_NUMERIC">
            <cfprocparam type="in" 
value="#variables.ResultFirms['firmno'][threadIndex]#" 
CFSQLType="CF_SQL_NUMERIC">
            <cfprocparam type="in" value="#threadPathDate#" 
CFSQLType="CF_SQL_NUMERIC">
        </cfstoredproc>
       
        <cfstoredproc procedure="REPORT_UTILS.insertRenewalProductsForFirm"
            dataSource = "#LIC_DSN#">
            <cfprocparam type="in" value="#thread.vRenewalSeq#" 
CFSQLType="CF_SQL_NUMERIC">
            <cfprocparam type="in" 
value="#ResultFirms['firmno'][threadIndex]#" CFSQLType="CF_SQL_NUMERIC">
        </cfstoredproc>
       
        <cfcatch type="any">
            <cflock name="treadLogLock" timeout="5" type="exclusive">
                    <cfset thread.cfcatch = duplicate(cfcatch)>
            </cflock>
        </cfcatch>
    </cftry>
    </cfthread>

    <!--- Pause every x threads to allow garbage collection.  --->
    <cfif i MOD 10 EQ 0>
        <cfthread action="join" name="#variables.threads#" timeout="2500"/>
       
        <!---  Loop over threads and kill any hanging threads --->
        <cfloop collection="#cfThread#" item="th">
            <cfif cfThread[th].status NEQ 'COMPLETED'>
                <cfthread action="terminate" name="#th#"/>
            </cfif>
        </cfloop>
<h2>SLEEPING 
<cfoutput>#timeFormat(now(),"hh:mm:ss:l")#</cfoutput></h2>       
        <cfset sleep(10000)>
        <cfset variables.threads = "">
        </ul><ul>
    </cfif>
</cfloop>
</ul>

<h2>DONE</h2>
<cfthread action="join" name="#structKeyList(cfThread)#" timeout="10000" />

<!---  Loop over threads and kill any hanging threads --->
<cfloop collection="#cfThread#" item="th">
    <cfif cfThread[th].status NEQ 'COMPLETED'>
        <cfthread action="terminate" name="#th#"/>
    </cfif>
</cfloop>

<cfoutput>
<ul>
<cfloop collection="#cfThread#" item="th">
    <li style="margin-top: .5em;">#th#
        <ul>
        <cfloop collection="#cfThread[th]#" item="key">
           
            <li>#key#: &nbsp; <cfif 
isSimpleValue(cfThread[th][key])>#cfThread[th][key]#<cfelse><cfdump 
var="#cfThread[th][key]#"></cfif></li>
        </cfloop>
        </ul>
    </li>
</cfloop>
</ul>
</cfoutput>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;203748912;27390454;j

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:308739
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to