I have One Callable which I invoked using
FutureTask<Integer> task = new FutureTask<Integer>(new MyCallable(name, type));
pool = Executors.newSingleThreadExecutor();
pool.submit(task);
I want to know Is execution is continue after pool.submit(task) or It will wait for callable to complete its execution?
In short I just want to know is there any method like thread.join() for Callable?
The
pool.submit(callable)method returns aFutureand will start executing immediately if the threads are available in the pool. To do ajoin, you can callfuture.get()which joins with the thread, returning the value returned by thecall()method. It is important to note thatget()may throw anExecutionExceptionif thecall()method threw.You do not need to wrap your
Callablein aFutureTask. The thread-pool does that for you. So your code would be:This is if your
MyCallableimplementsCallable<String>of course. TheFuture<?>will match whatever type yourCallableis.