KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > lock > NonBlockingWriterLock


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.cache.lock;
9
10 /**
11  * NonBlockingWriterLock is a read/write lock (with upgrade) that has
12  * non-blocking write lock acquisition on existing read lock(s).
13  * <p>Note that the write lock is exclusive among write locks, e.g.,
14  * only one write lock can be granted at one time, but the write lock
15  * is independent of the read locks. For example,
16  * a read lock to be acquired will be blocked if there is existing write lock, but
17  * will not be blocked if there are mutiple read locks already granted to other
18  * owners. On the other hand, a write lock can be acquired as long as there
19  * is no existing write lock, regardless how many read locks have been
20  * granted.
21  *
22  * @author Ben Wang
23  * @version $Id: NonBlockingWriterLock.java,v 1.3 2006/12/11 21:14:34 genman Exp $
24  */

25 public class NonBlockingWriterLock extends ReadWriteLockWithUpgrade
26 {
27
28    // Only need to overwrite this method so WL is not blocked on RL.
29
protected synchronized boolean startWrite()
30    {
31       boolean allowWrite = (activeWriter_ == null);
32       if (allowWrite) activeWriter_ = Thread.currentThread();
33       return allowWrite;
34    }
35 }
36
Popular Tags