Java Executor

How to Shutdown a Java ExecutorService

Learn ExecutorService shutdown(), shutdownNow() and awaitTermination​() APIs and how to use them correctly to shutdown executor under different conditions,

Java 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()

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.

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 tasks get rejected Remember when we finish the execution of an executor, we use the shutdown() method. The executor waits for the completion of tasks …

Guide to ExecutorService in Java

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.

Java Fixed Size Thread Pool Executor Example

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 look example of fixed size thread pool executor which will help in improved performance and better system resource utilization by limiting the maximum number of …

Java Thread Pools and ThreadPoolExecutor

Why do we need a thread pool in Java? The answer is when we develop a simple, concurrent application in Java, we create some Runnable objects and then create the corresponding Thread objects to execute them. Creating a thread in Java is an expensive operation. And if you start creating …

Throttling Task Submission Rate in Java

1. Introduction In BlockingQueue and ThreadPoolExecutor example, we learned creating a CustomThreadPoolExecutor which had the following capabilities: Tasks are being submitted to the blocking queue. An executor picks up the task from the queue and execute them. It had overridden beforeExecute() and afterExecute() methods to perform pre-and-post activities if needed. …

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.