Code example for ReadWriteLock

Methods: readLock, writeLock

0
 */ 
 
public class SynchronizeCollectionWithLockVariable { 
    private final Map<String, Data> m = new HashMap<String, Data>(); 
    private final ReadWriteLock rwl = new ReentrantReadWriteLock(); 
    private final Lock r = rwl.readLock(); 
    private final Lock w = rwl.writeLock(); 
 
    public Data correctGet(String key) { 
        r.lock(); 
        try { 
        	DBManager db=new DBManager(); 
        	db.process(); 
            return m.get(key); 
        } finally { 
            r.unlock(); 
        } 
    } 
     
    public void justOneLockStatement(){ 
    	 r.lock();