Java 5 introduces general purpose synchronization classes, including semaphores, mutexes, barriers, latches, and exchangers, which facilitate coordination between threads. These classes are a apart of the java.util.concurrent package. A brief description of each of these follows:
Semaphores
A counting semaphore maintains a set of permits. Each acquire() blocks if necessary until a permit is available, and then takes it. Each release() adds a permit, potentially releasing a blocking acquirer. However, no actual permit objects are used; the Semaphore just keeps a count of the number available and acts accordingly.
Semaphores are often used to restrict the number of threads than can access some (physical or logical) resource.
Barrier
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 group 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.
Exchangers
A synchronization point at which two threads can exchange objects. Each thread presents some object on entry to the exchange method, and receives the object presented by the other thread on return.
Latches
A synchronization aid that allows one or more threads to wait until a set of operations being performed in other threads completes. 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.
For Sample code and more details about Java 5 synchronizers, see the article "GETTING TO KNOW SYNCHRONIZERS" at java.sun.com.
Tuesday, November 21, 2006
Subscribe to:
Post Comments (Atom)
Popular Posts
-
This post will describe how to create and deploy a Java Web Application war to Heroku using Heroku CLI. You will need a basic understanding ...
-
In this post we will see how to do an offline install Jenkins and required plugins on a Red Hat Enterprise Linux Server release 7.3. This is...
-
Update: A new post for validation in struts with annotation is available at: Struts 2 Validation: Annotations . Struts 2.0 relies on a val...
-
Google has opensourced it's Google Web Toolkit . The project is now fully opensource under the Apache 2.0 license . The new 1.3 RC has...
-
The previous post described the Strategy pattern in brief. I listed out where and why the strategy pattern may be used. This post describes...
-
In a previous post, I described how to use Quartz scheduler for scheduling . In this post, I describe the configuration changes required for...
-
Java 8 introduced default and static methods, the previous post gives a few examples of Java 8 default and static methods . Java 9 builds on...
-
Tivoli Access Manager Configuration Steps for using AznAPI: 1.) Configure AMRTE 2.) Configure AMJRTE (This will install the necessary librar...
-
The previous post described the Command pattern in brief. I listed out where and why the command pattern may be used. This post describes h...
-
Just moved to blogger beta. Testing the changes.
No comments:
Post a Comment