| ||||
|
Code - Class EDU.oswego.cs.dl.util.concurrent.SyncSet1 /* 2 File: SyncSet.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 import java.util.*; 16 17 /** 18 * SyncSets wrap Sync-based control around java.util.Sets. 19 * They support two additional reader operations than do 20 * SyncCollection: hashCode and equals. 21 * <p>[<a HREF="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>] 22 * @see SyncCollection 23 **/ 24 25 26 public class SyncSet extends SyncCollection implements Set { 27 28 /** 29 * Create a new SyncSet protecting the given collection, 30 * and using the given sync to control both reader and writer methods. 31 * Common, reasonable choices for the sync argument include 32 * Mutex, ReentrantLock, and Semaphores initialized to 1. 33 **/ 34 public SyncSet(Set set, Sync sync) { 35 super (set, sync); 36 } 37 38 /** 39 * Create a new SyncSet protecting the given set, 40 * and using the given ReadWriteLock to control reader and writer methods. 41 **/ 42 public SyncSet(Set set, ReadWriteLock rwl) { 43 super (set, rwl.readLock(), rwl.writeLock()); 44 } 45 46 /** 47 * Create a new SyncSet protecting the given set, 48 * and using the given pair of locks to control reader and writer methods. 49 **/ 50 public SyncSet(Set set, Sync readLock, Sync writeLock) { 51 super(set, readLock, writeLock); 52 } 53 54 public int hashCode() { 55 boolean wasInterrupted = beforeRead(); 56 try { 57 return c_.hashCode(); 58 } 59 finally { 60 afterRead(wasInterrupted); 61 } 62 } 63 64 public boolean equals(Object o) { 65 boolean wasInterrupted = beforeRead(); 66 try { 67 return c_.equals(o); 68 } 69 finally { 70 afterRead(wasInterrupted); 71 } 72 } 73 74 } 75 76 77 |
|||
Java API By Example, From Geeks To Geeks. |
Conditions of Use |
About Us
© 2002 - 2005, KickJava.com, or its affiliates
|