3

I have one webservice which is called by client.

public class MyWebServiceClass {
    public int myMethod() {
        myAsyncMethodInAnotherClass();
        return 2;
    }
}

I have another class which is acync, this class have method

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();
}

I want myMethod() inside MyWebServiceClass should return 2 to the client, without waiting for process inside myAsyncMethodInAnotherClass(). Though I have created executorService but it is still waiting for method to complete before returning 2.

0 Answers0