Java ExecutorService submit() method Example

ExecutorService submit() method

submit(Callable<T> task)

Submits a value-returning task for execution and returns a Future representing the pending results of the task. The Future's get method will return the task's result upon successful completion.
If you would like to immediately block waiting for a task, you can use constructions of the form result = exec.submit(aCallable).get();

Note: The Executors class includes a set of methods that can convert some other common closure-like objects, for example, PrivilegedAction to Callable form so they can be submitted.

submit(Runnable task, T result)

Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return the given result upon successful completion.

submit(Runnable task)

Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return null upon successful completion.

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)