public void run() { float f; if (getName().startsWith("R")) locker.enterAppThread(); else locker.enterLockerThread(); for (int i = 0; i < 500000000; i++) f = (float) i; if (getName().startsWith("R")) locker.exitAppThread(); else locker.exitLockerThread(); }
public static void main(String[] args) { JavaConcurrencyReentrantReadWriteLocker locker = new JavaConcurrencyReentrantReadWriteLocker(); locker.init(null); T[] readers = new T[24]; T[] writers = new T[5]; for (int i = 0; i < 12; i++) { readers[i] = locker.new T("Reader " + i, locker); readers[i].start(); } for (int i = 0; i < writers.length; i++) { writers[i] = locker.new T("Writer " + i, locker); writers[i].start(); } for (int i = 12; i < 24; i++) { readers[i] = locker.new T("Reader " + i, locker); readers[i].start(); } }