I have the following Java code:
final Future future = exeService.submit( new Runnable() { public void run() { myObject.doSomething(); } } ); future.get();
where exeService is an instance
java.util.concurrent.ExecutorService
The problem is that myObject.doSomething() never returns, and therefore future.get() never returns.
However, if I replaced the call with submit execute call as follows:
exeService.execute( new Runnable() { public void run() { myObject.doSomething(); } } );
a call to myObject.doSomething() returned. I don't know if this matters, but doSomething() is the void method.
Why doSomething() end when using execute , but not when using submit ?
In addition, I do not need to use future.get() ; which seemed like the most natural way to do this. (I also encounter the same problem with CountdownLatch .) The fact is that I need to wait until doSomething() before continuing, and for complex reasons I will not go into it here, I need to run it on a separate thread. If there is another way to do this, it will be fine.
source share