ExecutorService

The standard-library service that owns a pool of worker threads and runs tasks you submit to it, returning a Future for each.

In more detail

Submitting tasks to an executor separates what to run from how threads are managed. The pool limits how many tasks run at once, and its queue holds the rest. Whoever creates an executor owns it and must call shutdown, otherwise its threads can keep the process alive.

Examples

ExecutorService pool = Executors.newFixedThreadPool(2);
pool.shutdown();

Related terms

Taught in

References

Certification courses