KickJava   Java API By Example, From Geeks To Geeks.

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


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

7 package org.jboss.cache.lock;
8
9 import java.util.concurrent.locks.Lock JavaDoc;
10
11 //import org.jboss.logging.Logger;
12

13 /**
14  * Lock strategy of Serializable that prevents dirty read, non-repeatable read, and
15  * phantom read.
16  * <p> Dirty read allows (t1) write and then (t2) read within two separate threads, all without
17  * transaction commit. </p>
18  * <p> Non-repeatable read allows (t1) read, (t2) write, and then (t1) read, all without
19  * transaction commit. </p>
20  * <p> Phantom read allows (t1) read n rows, (t2) insert k rows, and (t1) read n+k rows.</p>
21  *
22  * @author <a HREF="mailto:bwang00@sourceforge.net">Ben Wang</a> July 15, 2003
23  * @version $Revision: 1.4 $
24  */

25 public class LockStrategySerializable implements LockStrategy
26 {
27 // Log log=LogFactory.getLog(getClass());
28

29    private SemaphoreLock sem_;
30
31    public LockStrategySerializable()
32    {
33       sem_ = new SemaphoreLock(1);
34    }
35
36    /**
37     * @see org.jboss.cache.lock.LockStrategy#readLock()
38     */

39    public Lock JavaDoc readLock()
40    {
41       return sem_;
42    }
43
44    /**
45     * @see org.jboss.cache.lock.LockStrategy#upgradeLockAttempt(long)
46     */

47    public Lock JavaDoc upgradeLockAttempt(long msecs) throws UpgradeException
48    {
49       // If we come to this far, that means the thread owns a rl already
50
// so we just return the same lock
51
return sem_;
52    }
53
54    /**
55     * @see org.jboss.cache.lock.LockStrategy#writeLock()
56     */

57    public Lock JavaDoc writeLock()
58    {
59       return sem_;
60    }
61 }
62
Popular Tags