我有一个由客户端调用的Web服务。
public class MyWebServiceClass {
public int myMethod() {
myAsyncMethodInAnotherClass();
return 2;
}
}
我有另一个是acync的类,这个类有方法
public void myAsyncMethodInAnotherClass() throws InterruptedException, ExecutionException {
final Receiver receiver = new Receiver();
ExecutorService executorService = Executors.newFixedThreadPool(10);
Future future = executorService.submit(new Runnable() {
public void run() {
System.out.println("Asynchronous task");
receiver.doSomeThingElse();
}
});
executorService.shutdown();
}
我希望myMethod()
内的MyWebServiceClass
应该返回2到客户端,而不必等待myAsyncMethodInAnotherClass()
内的进程。虽然我创建了executorService
,但它仍然在等待方法完成才返回2。