GWT中的每个RPC都有1分钟的超时限制,并且这是不可配置的。
我正在使用来自第三方提供商(称为WEBSERVICE)的SYNC METHOD。
有时,此METHOD(网络服务)挂起超过1分钟,并使我的RPC崩溃。问题是我无法在服务器端捕获此异常,我需要回滚一些标志(它的处理更为复杂,仅作为示例)
try {
...my code goes here...
MYTHIRDPARTYWS ws = new MYTHIRDPARTYWS()
String RESULT = ws.run;
...my code needs to take action depending of the result...
} catch (Exception e) {
...my code needs to take action depending of the exception...
}
我需要这样的东西:
try {
...my code goes here...
Process p = new Process() {
MYTHIRDPARTYWS ws = new MYTHIRDPARTYWS()
String RESULT = ws.run;
};
p.setTimeOut(40000);
p.run;
...my code needs to take action depending of the result...
} catch (Exception e) {
...my code needs to take action depending of the exception...
}
任何的想法?
使用方法ExecutorService.execute()在后台线程中生成某些任务。
遵循的步骤:
web.xml
servletinit()
方法中读取一些初始化参数,例如超时和线程池大小
AsyncContext
通过request.startAsync()
在doGet()或doPost()方法中调用HTTP来获取onComplete()
,onTimeout()
,onError()
,onStartAsync()
ExecutorService.execute()
以在后台线程中生成某些任务我已经在这里发布了代码异步servlet不异步运行
请看一下,让我知道是否有任何混淆。真的行。您可以完全控制子流程的每个生命周期方法,以处理任何类型的异常。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句