{@code}class RWDictionary private final Mapm = new TreeMap (); private final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock(); private final Lock r = rwl.readLock(); private final Lock w = rwl.writeLock(); public Data get(String key) { r.lock(); try { return m.get(key); } finally { r.unlock(); } } public String[] allKeys() { r.lock(); try { return m.keySet().toArray(); } finally { r.unlock(); } } public Data put(String key, Data value) { w.lock(); try { return m.put(key, value); } finally { w.unlock(); } } public void clear() { w.lock(); try { m.clear(); } finally { w.unlock(); } } }}
This lock supports a maximum of 65535 recursive write locks and 65535 read locks. Attempts to exceed these limits result in {@link Error} throws from locking methods. @since 1.5 @author Doug Lea
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|