Code example for ReentrantReadWriteLock

Methods: readLock, writeLock

0
 * @since 1.0 
 *  
 */ 
public class ReadLockAndWriteLockSeparate { 
 
	private final ReentrantReadWriteLock rrwl = new ReentrantReadWriteLock();
	private final Lock readLock = rrwl.readLock();
	private final Lock writeLock = rrwl.writeLock();
//	private volatile int count = 0; 
	private int count = 0;
	 
	public void read() { 
		try { 
			readLock.lock();
			System.out.println("count = " + count);
			Thread.sleep(1000);
			System.out.println("正在读... count = " + count);
		} catch (InterruptedException e) {
			e.printStackTrace();
		} finally { 
			readLock.unlock();