我有一个无状态的 EJB-3.1 会话 bean,其中包含一个异步方法,该方法执行一些昂贵的处理并将未来返回给客户端,从而允许它在准备好后显示处理结果:
@Asynchronous
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public Future<String> importModules() {
String result = doSomeHeavyStuff();
return new AsyncResult<String>(result);
}
这个 bean 在 JBoss 6 实例上运行并从 Swing 客户端远程调用:
final Future<String> termination =
Proxy.getProxy().getMenfpImportService().importModules();
SwingWorker<String, Object> worker = new SwingWorker<String, Object>() {
@Override
protected String doInBackground() {
/* ... */
if (termination.isDone()) {
return termination.get();
}
/* ... */
}
/* ... */
}
虽然处理通常成功完成,但某些计算需要超过 300 秒才能完成。
对于这些计算,JBoss 套接字超时会导致客户端在调用 terminate.get() 时收到 ExecutionException 而不是计算结果:
10:26:16,301 INFO Application:1150 - Execution exception during modules import:
java.util.concurrent.ExecutionException: org.jboss.remoting.InvocationFailureException: Socket timed out. Waited 300000 milliseconds for response while calling on InvokerLocator [socket://degotte:3873/?timeout=300000]; nested exception is:
java.net.SocketTimeoutException: Read timed out
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:222)
at java.util.concurrent.FutureTask.get(FutureTask.java:83)
at org.jboss.ejb3.async.spi.AsynchronousClientFuture.get(AsynchronousClientFuture.java:113)
at org.jboss.ejb3.async.impl.util.concurrent.LocalJvmSerializableFutureWrapper.get(LocalJvmSerializableFutureWrapper.java:161)
at lu.lippmann.forminitiale.client.gui.Application$2.doInBackground(Application.java:1137)
at lu.lippmann.forminitiale.client.gui.Application$2.doInBackground(Application.java:1)
at javax.swing.SwingWorker$1.call(SwingWorker.java:277)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at javax.swing.SwingWorker.run(SwingWorker.java:316)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
不幸的是,@Asynchronous 注解没有提供任何配置选项。
我的问题是如何增加客户端服务器通信套接字超时,以及是否以任何方式可能仅用于在调用异步方法期间建立的连接。
谢谢,托马斯