【问题标题】:GWT Create a sub-process in server sideGWT 在服务器端创建子进程
【发布时间】:2014-03-11 00:59:26
【问题描述】:

GWT 中的每个 RPC 都被限制为 1 分钟超时,这是不可配置的。

我正在使用来自调用 WEBSERVICE 的第三方提供商的 SYNC 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...

}

有什么想法吗?

【问题讨论】:

    标签: java web-services google-app-engine gwt gwt-rpc


    【解决方案1】:

    使用方法 ExecutorService.execute() 在后台线程中生成一些任务。

    要遵循的步骤:

    • 在servletinit()方法中从web.xml中读取一些init参数,比如timeout和threadpoolsize
      • timeout参数用于设置Async线程的超时时间
      • threadpoolsize 用于创建异步线程池
    • 通过在 doGet() 或 doPost() 方法中调用 HTTP request.startAsync() 获取 AsyncContext
    • 设置 AsyncContext 的超时时间
    • 附加监听器以响应此 AsyncContext 的生命周期事件,例如 onComplete()onTimeout()onError()onStartAsync()
    • 调用 ExecutorService.execute() 在后台线程中生成一些任务

    我已经把代码贴在这里Asynchronous servlet not acting asynchronously

    如果有任何混淆,请查看并告诉我。真的行。 您可以完全控制子流程的每个生命周期方法来处理任何类型的异常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多