In this tutorial you will see how to write test case on Java thread using junit. Writing junit to test thread in Java will show an example on single threaded environment. Prerequisites Java 8 Eclipse Gradle It is advisable to structure the code in such a way so that the code could be easily tested […]
Semaphore is used to control the number of threads that can access a resource. The Semaphore class in the java.util.concurrent package represents the semaphore synchronizer.
In this tutorial I am going to show how to create custom thread pool in Java. Multi-threaded and multi-process programming is a great way to optimize CPU usage and get things done quickly. Creation of Threads in Java is a costly IO operation. Therefore it is not advisable to create & destroy thread(s) every often. […]
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 […]
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 […]
What is BlockingQueue ? A blocking queue is a queue that blocks when you try to dequeue an empty queue, or if you try to enqueue items in a full queue. A thread trying to dequeue from an empty queue is blocked until some other threads insert an item into the queue. A thread trying […]
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 […]
Introduction We 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 of the threads of an Object share its variables, so if the variable is not thread safe, then we will […]