Java Concurrency – Multi Threading with ExecutorService

Multi Threading with ExecutorService In this post we'll look how the ExeutorService can be used to run multi-threaded asynchronous tasks. We'll start by creating threads directly and then move on to explore the ExeutorService and how it can be used to simplify things. Creating Threads Directly Before the Executor API came along, developers were responsible for instantiating and managing threads directly. Let's look at a simple example below. /** * Call 2 expensive methods on separate threads * * @throws InterruptedException */ public void doMultiThreadedWork() throws InterruptedException { /* create Runnable using anonymous inner class */ Thread t1 = new Thread(new Runnable() { public void [...]