gpt4 book ai didi

coldfusion - 如何在 ColdFusion 中运行多线程

转载 作者:行者123 更新时间:2023-12-05 06:46:14 25 4
gpt4 key购买 nike

我正在尝试在 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>

有什么想法吗?

最佳答案

好吧,我决定不使用 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>

关于coldfusion - 如何在 ColdFusion 中运行多线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17596834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com