【发布时间】:2008-12-23 21:42:14
【问题描述】:
我有一个 Web 应用程序,它在 Windows/IIS 服务器上使用 ColdFusion 8 批量生成数百个 PDF。
该过程在我的开发和登台服务器上运行良好,但客户端当然很便宜,而且只为共享主机付费,这不如我的开发/登台盒快。因此,PDF 生成线程超时。
流程是这样的:
- 运行页面以生成 PDF。
- 运行查询以确定需要生成哪些 PDF,然后循环为需要生成的每个 PDF 触发应用程序范围的 UDF 调用。
- UDF 查找给定项目的信息,然后为 PDF 生成创建一个线程,以防止生成拖慢页面。
- 线程只是使用 CFDocument 创建 PDF 并将其保存到磁盘,然后终止。
线程不会重新加入,并且没有任何东西在等待它们中的任何一个完成。进行 UDF 调用的页面在几毫秒内完成;是线程本身超时。
这里是 UDF(和线程创建)的代码:
<cffunction name="genTearSheet" output="false" returntype="void">
<cfargument name="partId" type="numeric" required="true"/>
<!--- saveLocation can be a relative or absolute path --->
<cfargument name="saveLocation" type="string" required="true"/>
<cfargument name="overwrite" type="boolean" required="false" default="true" />
<cfset var local = structNew() />
<!--- fix save location if we need to --->
<cfif left(arguments.saveLocation, 1) eq "/">
<cfset arguments.saveLocation = expandPath(arguments.saveLocation) />
</cfif>
<!--- get part info --->
<cfif structKeyExists(application, "partGateway")>
<cfset local.part = application.partGateway
.getByAttributesQuery(partId: arguments.partId)/>
<cfelse>
<cfset local.part = createObject("component","com.admin.partGateway")
.init(application.dsn).getByAttributesQuery(partId: arguments.partId)/>
</cfif>
<!--- define file name to be saved --->
<cfif right(arguments.saveLocation, 4) neq ".pdf">
<cfif right(arguments.saveLocation, 1) neq "/">
<cfset arguments.saveLocation = arguments.saveLocation & "/" />
</cfif>
<cfset arguments.saveLocation = arguments.saveLocation &
"ts_#application.udf.sanitizePartNum(local.part.PartNum)#.pdf"/>
</cfif>
<!--- generate the new PDF in a thread so that page processing can continue --->
<cfthread name="thread-genTearSheet-partid-#arguments.partId#" action="run"
filename="#arguments.saveLocation#" part="#local.part#"
overwrite="#arguments.overwrite#">
<cfsetting requestTimeOut=240 />
<cftry>
<cfoutput>
<cfdocument format="PDF" marginbottom="0.75"
filename="#attributes.fileName#" overwrite="#attributes.overwrite#">
<cfdocumentitem type="footer">
<center>
<font face="Tahoma" color="black" size="7pt">
pdf footer text here
</font>
</center>
</cfdocumentitem>
pdf body here
</cfdocument>
</cfoutput>
<cfcatch>
<cfset application.udf.errorEmail(application.errorEmail,
"Error in threaded PDF save", cfcatch)/>
</cfcatch>
</cftry>
</cfthread>
</cffunction>
如您所见,我已尝试将<cfsetting requestTimeout=240 /> 添加到线程顶部以尝试使其寿命更长...没有骰子。当我看到the CFThread tag has a timeout parameter 时,我也有点兴奋,但后来意识到它只适用于加入线程(action=join)。
在 ColdFusion Administrator 中更改默认超时不是一个选项,因为这是一个共享主机。
如果有人对如何使这些线程寿命更长有任何想法,我将不胜感激。
【问题讨论】:
-
你怎么知道线程超时了?我对 Enterprise 不是特别熟悉,但在我的 Standard 框中,抛出的线程似乎没有超时。
-
我通过 Application.cfc 的 onError() 方法收到错误电子邮件,该方法在线程超时时调用。此外,托管服务提供商告诉我错误日志中显示了相同的消息。
标签: multithreading coldfusion timeout