Mercurial > hg > blitz_condensed
comparison src/EDU/oswego/cs/dl/util/concurrent/NullSync.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dc0c5604566 |
---|---|
1 /* | |
2 File: NullSync.java | |
3 | |
4 Originally written by Doug Lea and released into the public domain. | |
5 This may be used for any purposes whatsoever without acknowledgment. | |
6 Thanks for the assistance and support of Sun Microsystems Labs, | |
7 and everyone contributing, testing, and using this code. | |
8 | |
9 History: | |
10 Date Who What | |
11 1Aug1998 dl Create public version | |
12 */ | |
13 | |
14 package EDU.oswego.cs.dl.util.concurrent; | |
15 | |
16 /** | |
17 * A No-Op implementation of Sync. Acquire never blocks, | |
18 * Attempt always succeeds, Release has no effect. | |
19 * However, acquire and release do detect interruption | |
20 * and throw InterruptedException. Also, the methods | |
21 * are synchronized, so preserve memory barrier properties | |
22 * of Syncs. | |
23 * <p> | |
24 * NullSyncs can be useful in optimizing classes when | |
25 * it is found that locking is not strictly necesssary. | |
26 * | |
27 * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>] | |
28 **/ | |
29 | |
30 | |
31 public class NullSync implements Sync { | |
32 | |
33 public synchronized void acquire() throws InterruptedException { | |
34 if (Thread.interrupted()) throw new InterruptedException(); | |
35 } | |
36 | |
37 public synchronized boolean attempt(long msecs) throws InterruptedException { | |
38 if (Thread.interrupted()) throw new InterruptedException(); | |
39 return true; | |
40 } | |
41 | |
42 public synchronized void release() {} | |
43 | |
44 | |
45 } | |
46 | |
47 |