Implementing a Runnable vs Extending a Thread 1. Introduction “Should I implement a Runnable or extend the Thread class”? is quite a common question. In this article, we’ll see which approach makes more sense in practice and why. 2. Using Thread Let’s first define a SimpleThread class that extends Thread:… Continue Reading java-runnable-vs-extending-thread

An Introduction to Atomic Variables in Java 1. Introduction Simply put, shared state very easily leads to problems when concurrency is involved. If access to shared mutable objects is not managed properly, applications can quickly become prone to some hard-to-detect concurrency errors. In this article, we’ll revisit the use of… Continue Reading java-atomic-variables

A Guide to the Java ExecutorService 1. Overview ExecutorService is a framework provided by the JDK which simplifies the execution of tasks in asynchronous mode. Generally speaking, ExecutorService automatically provides a pool of threads and API for assigning tasks to it. Further reading: Guide to the Fork/Join Framework in Java… Continue Reading java-executor-service-tutorial

Guide to java.util.concurrent.BlockingQueue 1. Overview In this article, we will look at one of the most useful constructs java.util.concurrent to solve the concurrent producer-consumer problem. We’ll look at an API of the BlockingQueue interface and how methods from that interface make writing concurrent programs easier. Later in the article, we… Continue Reading java-blocking-queue