Reputation: 3890
Do I need to call future.get periodically to check whether the task is executed or not?
ExecutorService executor = Executors.newSingleThreadExecutor();
@SuppressWarnings("unchecked")
public void start(final file avo) throws IOException
{
Future future = executor.submit(new Callable(){
@Override
public Object call() throws Exception {
Condee conv = new Condee();
return conv.doChange(file);
});
LOG.debug("Finished the execution serverion");
executor.shutdown();
}
Upvotes: 0
Views: 118
Reputation: 68715
Try to retrieve the value sing the get method. You will either get the result or an exception will be thrown. Here are the four possibilities when you call the get on future:
Upvotes: 0
Reputation: 618
To check completion you can use future.isDone(), this needs to be constantly checked.
But if you use future.get(), this method will wait until finished and then return the result.
Upvotes: 2
Reputation: 4914
Add a call to this before executor.shutdown();
future.get();
This method will only return when it has completed.
Upvotes: 1