How to create Custom Thread Pool in Java

Introduction In this tutorial I am going to show how to create custom thread pool in Java. Multi-threaded and multi-process programmings are great ways to optimize CPU usage and get things done quickly. What is thread pool? Thread pool is a collection of already created worker threads ready to perform certain tasks. Instead of creating and discarding thread once the…

Java CyclicBarrier

A synchronization aid that allows a set of threads to all wait for each other to reach a common barrier point. CyclicBarriers are useful in programs involving a fixed sized party of threads that must occasionally wait for each other. The barrier is called cyclic because it can be re-used after the waiting threads are released. A CyclicBarrier supports an…

Java CountDownLatch

What is CountDownLatch? A synchronization aid that allows one or more threads to wait until a set of operations being performed in other threads completes, i.e., a kind of synchronization tool that allows one Thread  to wait for one or more Threads before it starts processing. How does CountDownLatch work? A CountDownLatch is initialized with a given count. The await…

BlockingQueue in Java

Blocking Queue A blocking queue is a queue that blocks when you try to dequeue an empty queue, or if you try to enqueue an item in a full queue. Dequeue means when you take an item out of a queue. Enqueue means when you put an item into a queue. A thread trying to dequeue an empty queue is…

How to concurrently execute tasks using Java in Spring

This tutorials will show you how we can concurrently execute different operations using Java utility class called java.util.concurrent.Executors in Spring framework. Spring supports XML as well as Programmatic configuration of beans but, here we will use XML based metadata configuration. If you already have an idea on how to create a maven project in Eclipse will be great otherwise I…

How ThreadLocal Works In Java

Introduction Here you will see how ThreadLocal works in Java. Java ThreadLocal class is used to create thread-local variables. The thread-local variable can be read and written by the same thread only. In multi-threaded environments all threads of an Object share their variables, so if the variable is not thread safe, then an inconsistent state of the variable occurs. Therefore…