coldfusion - 限制被调用 CFC 的执行时间
问题描述
我们有一个 ColdFusion 编辑,它检查 MX 记录以软验证电子邮件地址。我们偶尔会收到来自 DNS 服务器的长响应,并且需要限制在放弃之前等待响应的时间。
调用的组件进行实际查找。下面复制的代码是 larver 验证脚本的一部分。
我想要做的是限制我将等待查找组件运行多长时间,然后在超过该时间时处理错误。这段代码对我来说似乎是正确的,但它只是超过了超时时间(我在组件中有一个“睡眠”来模拟缓慢的响应。)
try {
requesttimeout="10";
MyNewArray[1] = right(MyEmail, RightChars);
mycnt = new common.functions.mxLookup(MyNewArray);
Caller.EmailReturnCode = iif(mycnt gt 0,'"0"','"2"');
}
catch ("coldfusion.runtime.RequestTimedOutException" a) {
Caller.EmailReturnCode = "2";
}
catch (any e) {
Caller.EmailReturnCode = "2";
}
解决方案
thread action="run" name="doLookup" {
variables.mycnt = new common.functions.mxLookup(MyNewArray);
}
thread action="join" name="doLookup" timeout="20000";
if(doLookup.Status is "RUNNING"){
thread action="terminate" name="doLookup";
throw("MX Lookup of #MyEmail# timed out", "toException", "MX Lookup exceeded allowed time of 20 seconds at #timeFormat(now(),'HH:mm:sss')#");
}
Caller.EmailReturnCode = iif(mycnt gt 0,'"0"','"2"');
感谢亚历克斯
该解决方案完美运行。
推荐阅读
- ruby-on-rails - 我尝试安装 RubyGems,但现在出现了一些错误
- android - 更改android中的默认字符串xml文件
- python-3.x - AWS Lambda 到 DynamoDB 超时
- python - 在 Python 中制作 pi 数字的可视化表示
- amazon-web-services - 亚马逊网络服务 - Route53
- algorithm - 运动数据比较
- javascript - 使用 ajax 和现有表单数据上传文件
- mysql - 循环中的 bindParam 始终写入最后一个值
- excel - 将 Microsoft Project 对象库导入 Excel VBA 项目
- javascript - 如何在 mouseon 和 mouseout 上更改动画颜色?