感谢回复!!但我仍然无法做到这一点.我得到的错误是"类型objGet1在类型类coldfusion.runtime.VariableScope类型的Java对象中未定义."
以下是我的完整代码.我只想转储包含cfhttp信息的每个线程的值.
http://www.google.com/search?"&"q = Vin + Diesel"&"&num = 10"&"&start =")/>
<cfset intStartTime = GetTickCount() />
<cfloop index="intGet" from="1" to="10" step="1">
<!--- Start a new thread for this CFHttp call. --->
<cfthread action="run" name="objGet#intGet#">
<cfhttp method="GET" url="#strBaseURL##((intGet - 1) * 10)#" useragent="#CGI.http_user_agent#" result="THREAD.Get#intGet#" />
</cfthread>
</cfloop>
<cfloop index="intGet" from="1" to="10" step="1">
<cfthread action="join" name="objGet#intGet#" />
<cfdump var="#Variables['objGet'&intGet]#"><br />
</cfloop>
Run Code Online (Sandbox Code Playgroud)
当我在循环中加入线程后使用.我得到了预期的结果谢谢!!
如何在 Coldfusion 线程中使用函数参数?我不明白为什么会出现以下错误:
元素 SOMEID 在 ARGUMENTS 中未定义。
我的代码的简化示例。
public any function createSomeEntity(required numeric someId) {
thread action="run" name="someThread" {
var result = someFunction(someId = arguments.someId);
// some logic
}
thread action="join" name="someThread" timeout="5000";
if (someThread.status != "COMPLETED") {
// action 1
} else {
// action 2
}
}
Run Code Online (Sandbox Code Playgroud) 我以前没有使用过 cfthread,但我使用以下代码但它不起作用。
<cfloop from="1" to="5" index="local.pageNo">
<cfthread name="thr#local.pageNo#" threadIndex="#local.pageNo#" action="run">
<cfif local.pageNo GT 1>
<cfhttp url="#local.apiURL#&page=#local.pageNo#" method="get" result="local.myResults" >
</cfhttp>
<cfset local.myResponse = deserializejson(local.myResults.filecontent)>
</cfif>
<cfloop from="1" to="#arrayLen(local.myResponse.result)#" index="i">
<cfset local.apartmentList = listAppend(local.apartmentList,local.myResponse.result[i].id & '-0')>
</cfloop>
</cfthread>
</cfloop>
<cfthread action="join" name="thr1,thr2,thr3,thr4,thr5"/>
Run Code Online (Sandbox Code Playgroud)
我期望 local.apartmentList 是一个很大的 ID 列表,但它返回空。这几乎就像线程内的代码被跳过一样。有人能发现我做错了什么吗?
我正在创建一个简单的电子邮件服务器状态页面,该页面调用两个不同的 CFC。
状态页要求:
输出类似于以下内容:
MyServerName - <up arrow>
MyServerName2 - <up arrow>
MyServerName3 - <up arrow>
MyServerName4 -<down arrow>
代码:
RetrieveEmailServers = APPLICATION.selectQueries.RetrieveEmailServers()
if (RetrieveEmailServers.recordCount) {
for(i = 1; i <= RetrieveEmailServers.recordCount(); i++) {
LOCAL.theDomains = RetrieveEmailServers.check_servers_domain[i];
LOCAL.theNames = RetrieveEmailServers.check_servers_name[i];
thread action="run" name="thread#i#" theDomains="#LOCAL.theDomains#" theNames="#LOCAL.theNames#" {
VARIABLES.theServers = APPLICATION.emailCheck.checkSMTPServer('#domains#',25,'','');
}
}
thread action="join" …Run Code Online (Sandbox Code Playgroud) 我从CFThread得到了一个奇怪的错误.我把它包裹在一个在CFThread之外运行完美的函数.但是,它需要大约20秒才能完成,因此我将其拍摄到CFThread,然后将用户CFLocation到新页面并在完成后提醒他们.
它还包含在CFTRY中,如果出现问题,请给我发电子邮件.
我收到CFCATCH.Message所在的电子邮件:
"由于请求已经完成,CFThread无法将标头设置为响应"
我在Google上找不到任何类似错误的引用.我假设它不喜欢我在调用Thread后直接使用CFLocation的事实.所以,对于它的地狱,我尝试使用META REFRESH重定向用户.相同的错误结果.
有任何想法吗?
2013年7月8日更新:
代码在这里:
<cfset admsID = replace(createUUID(),"-","","all")>
<cfthread action="run" name="runADMS#admsID#" admsID="#admsID#" formstruct="#form#">
<cftry>
<cfobject component="cfc.AutoDealerBrandMarketShare" name="adms">
<cfset rptPDF = adms.buildReport(dealer=formstruct.chosenDealer,mkt=formstruct.DMACode,make=formstruct.Make,rptID=admsID)>
<cfcatch type="any">
<cfmail to="pmascari@mysite.com" from="techsupport@mysite.com" subject="ADMS Error">
Error occurred running a Polk Auto Dealer Market Share report.
#cfcatch.Message#
#cfcatch.detail#
</cfmail>
</cfcatch>
</cftry>
</cfthread>
<cflocation url="http://www.usercanwaithere.com">
Run Code Online (Sandbox Code Playgroud)