package edu.nyu.cs9053.concurrency.chapter14;

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

/**
 * User: blangel
 * Date: 7/20/14
 * Time: 3:02 PM
 */
public class Threads {

    public Thread states() {
        final Lock lock = new ReentrantLock();
        Thread thread = new Thread(new Runnable() {
            @Override public void run() {
                try {
                    synchronized (this) { // thread state when acquiring lock on 'this' ?
                        lock.lock(); // thread state when acquiring Lock ?
                        // do something ?
                    }
                    Thread.sleep(1000); // thread state when sleeping ?
                } catch (InterruptedException ie) {

                }
            }
        });
        System.out.printf("State = %s%n", thread.getState().name());
        thread.start();
        System.out.printf("State = %s%n", thread.getState().name());
        return thread;
    }

}
