GWT在服务器端创建子流程

保罗·赫克斯(Paul Chvx)

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.xmlservletinit()方法中读取一些初始化参数,例如超时和线程池大小
    • timeout参数用于设置异步线程的超时时间
    • threadpoolsize用于创建异步线程池
  • AsyncContext通过request.startAsync()在doGet()或doPost()方法中调用HTTP获取
  • 设置AsyncContext的超时
  • 连接监听器,响应这个AsyncContext的生命周期事件,例如onComplete()onTimeout()onError()onStartAsync()
  • 调用ExecutorService.execute()以在后台线程中生成某些任务

我已经在这里发布了代码异步servlet不异步运行

请看一下,让我知道是否有任何混淆。真的行。您可以完全控制子流程的每个生命周期方法,以处理任何类型的异常。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章