package edu.ptu.test.concurence;

import java.util.Objects;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by anshu.wang on 2016/3/29.
 */
public class LockTest {
    private int a;
    private int b;
    private Object o = new Object();
    private Lock l = new ReentrantLock();

    public void testSynchronized() {
        synchronized (LockTest.this) {
            a++;
        }
    }

    public void testLock() {
        l.lock();
        try {

        } catch (Exception e) {
        } finally {
            l.unlock();
        }
        try {
            Condition condition = l.newCondition();
            a++;
            condition.await();
            b++;
            condition.signalAll();
        } catch (Exception e) {

        }
    }

    public void testObjectWait() {
        try {

            a++;
            o.wait();
            b++;
            o.notifyAll();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}

@@ -1075,12 +1075,50 @@
  %7D%0A    %7D
+%0A    public void testVolatile()%7B%0A    %7D
 %0A%0A%7D%0A

add LockTestFile