Java Concurrency

Java DelayQueue

DelayQueue class is an unbounded blocking queue of delayed elements, in which an element can only be taken when its delay has expired.

ExecutorService – Cancel a task in executor

Learn to cancel a task submitted to an executor which is still has to be executed and has not been completed yet using cancel() method of Future object which allows you to make the cancellation operation.

ExecutorService invokeAll()

Learn to run multiple Callable tasks with ExecutorService.invokeAll(tasks) API and processing all the results returned from tasks in form of Future class instances in this ExecutorService Callable example.

ExecutorService invokeAny()

Last Updated:

Learn to use ExecutorService invokeAny() method where we execute multiple tasks at same time, but we make a decision asap any one of tasks is completed.

Callable Future Example

Last Updated:

Learn to execute callable tasks (which return a result of type Future after execution) using ExecutorService implementations in this simple Callable Future example.

Executor RejectedExecutionHandler

Learn to handle tasks which are submitted to Executor and are rejected because the executor has been shutdown for any reason using RejectedExecutionHandler. 1. When …

ExecutorService in Java

Last Updated:

Learn to use Java ExecutorService to execute a Runnable or Callable class in an asynchronous way. Also learn the various best practices to utilize it in most efficient manner in any Java application.

A Guide to AtomicInteger in Java

Last Updated:

The AtomicInteger class protects an underlying int value by providing methods that perform atomic operations on the value. It shall not be used as a replacement for an Integer class.

Producer Consumer Problem Using BlockingQueue

Last Updated:

BlockingQueue is excellent when you want to skip the complexity involved in wait–notify statements. This BlockingQueue can be used to solve the producer-consumer problem as …

Java Thread Life Cycle and Thread States

Last Updated:

A java thread can be in any of following thread states during it’s life cycle i.e. New, Runnable, Blocked, Waiting, Timed Waiting or Terminated. These …

Concurrency vs Parallelism

Last Updated:

Concurrency means multiple tasks which start, run, and complete in overlapping time periods, in no specific order. Parallelism is when multiple tasks OR several parts …

Java Multi-threading Evolution and Topics

Last Updated:

One of our reader, Anant, asked this extremely good question to elaborate / list down all related topics that we should know about multi-threading including …

Java Callable Future Example

Last Updated:

One of the benefits of the Java executor framework is that we can run concurrent tasks that may return a single result after processing the …

Java Fixed Size Thread Pool Executor Example

Last Updated:

In previous tutorial, we learned about basic thread pool executor with unlimited possible number of threads into the pool and it’s example usage. Now lets …


A blog about Java and its related technologies, the best practices, algorithms, interview questions, scripting languages, and Python.