package threaddemo;

public class ThreadStateWithWait {
    public static void main(String[] args) throws InterruptedException {
        Object object = new Object();

        Thread t1 = new Thread(() -> {
            synchronized (object) {
                try {
                    System.out.println("t1 will wait 100ms");
                    object.wait(100L);
                    System.out.println("t1 will wait");
                    object.wait();
                    System.out.println("t1 finished");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        t1.start();
        Thread.sleep(90L);

        synchronized (object) {
            System.out.println(STR."1.t1's state: \{t1.getState()}");
            object.notify();
            Thread.sleep(100L);
            System.out.println(STR."2.t1's state: \{t1.getState()}");
        }

        Thread.sleep(300L);
        System.out.println(STR."3.t1's state: \{t1.getState()}");

        Thread.sleep(100L);

        synchronized (object) {
            object.notify();
        }
        System.out.println(STR."4.t1's state: \{t1.getState()}");
        Thread.sleep(100L);
        System.out.println(STR."5.t1's state: \{t1.getState()}");
    }
}
