したがって、少し検索して学習した後、次の手順を実行してこの問題を解決しました。 @Asynchronous メソッドを含むステートレス Bean を作成しました。
@Asynchronous
public Future<String> sayHelloAsync()
{
//do something time consuming ...
return new AsyncResult<String>("Hello world");
}
次に、そのメソッドを Web サービスとして公開する 2 番目の Bean で、次のことを行いました。
@WebService
@Stateless
public class Test {
@EJB
FirstBean myFirstBean;//first bean containing the Async method.
/**
* Can be used in futher methods to follow
* the running web service method
*/
private Future<String> myAsyncResult;
@WebMethod
@WebResult(name = "hello")
public String sayHello(@WebParam(name = "timeout_in_seconds") long timeout)
{
myAsyncResult = myFirstBean.sayHelloAsync();
String myResult = "Service is still running";
if(timeout>0)
{
try {
myResult= myAsyncResult.get(timeout, TimeUnit.SECONDS);
} catch (InterruptedException e) {
myResult="InterruptedException occured";
} catch (ExecutionException e) {
myResult="ExecutionException occured";
} catch (TimeoutException e) {
myResult="The timeout value "+timeout+" was reached."+
" The Service is still running.";
}
}
return myResult;
}
}
タイムアウトが設定されている場合、クライアントはこの時間に達するまで待機します。私の場合、プロセスはまだ実行する必要があります。他の人に役立つことを願っています。