我正在尝试在ColdFusion中运行http请求的3个线程。这是一个电子邮件系统,它将选择3个不同的广告系列并同时向相应的收件人发送。
但是我的下面的代码只运行一个线程然后掉线。
<cfscript>
newsLetterCampaignGateway = createObject("component", "legacy.ssl.admin.news.model.newsLetterCampaignGateway");
newsLetterList = newsLetterCampaignGateway.getNewsLettersDueForSend();
//writedump(newsLetterList);abort;
</cfscript>
<cfloop query="newsLetterList" >
<cfset newsLetterId = newsLetterList.newsletterid>
<cfset campId = newsLetterList.id>
<cfset fromEmail = newsLetterList.fromEmail>
<!--- <cfdump var="#campId#"> --->
<cfthread action="run" name="runCampaign#campId#" >
<cflock
name="runCampaign_#campId#_Lock"
type="exclusive"
timeout="60">
<!--- <cfdump var="#campId#"> --->
<cfscript>
httpService = new http();
httpService.setMethod("get");
httpService.setCharset("utf-8");
httpService.setUrl("http://mysamplesite.com/legacy/ssl/admin/news/model/newsLettercampaign.cfc");
httpService.addParam(type="url",name="method",value="sendCampaignNewsLetters");
httpService.addParam(type="url",name="live",value="true");
httpService.addParam(type="url",name="campaignId",value="#campId#");
httpService.addParam(type="url",name="newsLetterId",value="#newsLetterId#");
httpService.addParam(type="url",name="fromEmail",value="#fromemail#");
httpService.send();
</cfscript>
</cflock>
</cfthread>
</cfloop>
<cfloop query="newsLetterList" >
<cfthread
action="join"
name="runCampaign#campId#"
/>
</cfloop>
任何想法的人?
答案 0 :(得分:0)
好吧,我决定不使用cfhttp并使用这样的线程,它可以工作。
<cfsetting requesttimeout="300000">
<cfscript>
newsLetterCampaignGateway = createObject("component", "path.to.cfc");
newsLetterList = newsLetterCampaignGateway.getNewsLettersDueForSend();
</cfscript>
<cfloop query="newsLetterList" >
<cftry>
<cfthread action="run" name="runCampaign#url.campaignId#" >
<cfset sendRequest(url)>
</cfthread>
<cfcatch>
<cfdump var="#cfcatch#"><cfabort>
</cfcatch>
</cftry>
</cfloop>
<cffunction name="sendRequest">
<cfargument name="urlStu" required="true">
<cfset newsLettercampaign = createObject("component", "path.to.cfc")>
<cfset newsLettercampaign.sendCampaignNewsLetters(arguments.urlStu)>
</cffunction>