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();
        }
    }
    public void testVolatile(){
    }

}

@@ -53,16 +53,107 @@
 bjects;%0A
+import java.util.Timer;%0Aimport java.util.TimerTask;%0Aimport java.util.concurrent.Semaphore;%0A
 import j
@@ -189,16 +189,16 @@
 dition;%0A
-
 import j
@@ -570,32 +570,81 @@
        %7D%0A    %7D%0A%0A
+    /**%0A     * %E4%BB%A3%E7%A0%81%E6%A8%A1%E6%9D%BF%EF%BC%8C%E5%85%B7%E4%BD%93%E5%8F%AF%E4%BB%A5%E7%9C%8B%E5%AE%98%E6%96%B9%E6%B3%A8%E9%87%8AReentrent%E6%B3%A8%E9%87%8A%0A     */%0A
     public void 
@@ -1240,19 +1240,428 @@
 test
-Volatile()%7B
+Timer()%7B%0A        Timer timer = new Timer(true);%0A        timer.schedule(new TimerTask() %7B%0A            @Override%0A            public void run() %7B%0A%0A            %7D%0A        %7D,0l);%0A    %7D%0A%0A    /**%0A     * %E4%BF%A1%E5%8F%B7%E9%87%8F%0A     */%0A    public void testSemaphore()%7B%0A        Semaphore semaphore = new Semaphore(5);%0A        try %7B%0A            semaphore.acquire();%0A        %7D catch (InterruptedException e) %7B%0A            e.printStackTrace();%0A        %7D
 %0A   

modify LockTestFile