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.
Continue reading “Semaphore – Java Concurrency”
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 optional
Runnable command that is run once per barrier point, after the last thread in the party arrives, but before any threads are released. This barrier action is useful for updating shared-state before any of the parties continue.
more information could be found at CyclicBarrier in Oracle
Continue reading “Java CyclicBarrier”
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 methods block until the current count reaches zero due to invocations of the countDown() method, after which all waiting threads are released and any subsequent invocations of await return immediately. This is a one-shot phenomenon — the count cannot be reset. If you need a version that resets the count, consider using a CyclicBarrier.
more information could be found at CountDownLatch in Oracle Document Continue reading “Java CountDownLatch”
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 to enqueue an item in a full queue is blocked until some other threads make space available in the queue, either by dequeuing one or more items or clearing the queue completely, it means a queue that additionally supports operations that wait for the queue to become non-empty when retrieving an element, and wait for space to become available in the queue when storing an element.
A BlockingQueue may be capacity bounded. At any given time it may have a remainingCapacity beyond which no additional elements can be put without blocking. A BlockingQueue without any intrinsic capacity constraints always reports a remaining capacity of Integer.MAX_VALUE. Continue reading “BlockingQueue in Java”
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 will tell you here how to create a maven project in Eclipse.
The following things are required in order to run the application
Have maven 3 installed and configured
Spring dependencies in pom.xml
Now we will see the below steps how to create a maven based spring project in Eclipse Continue reading “How to concurrently execute tasks using Java in Spring”