When work on the future is completed

Is the job Future considered complete isDone()==true

when it hits a return statement? For example:

ExecutorService executor = newSingleThreadExecutor();
Future<> result = executor.submit(new Runnable()
            {
                @Override
                public void run()
                {
                   return;
                }
            }

      

return

Is the result fulfilled when it hits ?

+3


source to share


2 answers


The Future.get

termination is considered the termination point a Future

.

To quote java docs

A The future is the result of asynchronous computation. Methods are provided to check whether a computation is complete, wait for it to complete, and get a computation result. The result can only be retrieved using the getter when the computation completes, blocking if necessary until it is ready. Cancellation is performed by the undo method Additional methods are provided to determine if a task ...



In other words, until the time is up Future

, the call Future.get

will be blocked and therefore completion Future.get

should be treated as completion Future

(normal or exceptional)

PS: Future.isDone

should only be used for checking status and not specified as on completion Future

.

+2


source


More or less. The Javadoc is ambiguous for what it exactly means, but usually, when the calls return, very soon after being isDone()

true (or if an exception is thrown, the same is true).



+3


source







All Articles