package threaddemo;

public class ThreadStateWithJoin {

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });

        Thread t2 = new Thread(() -> {
            try {
                System.out.println("t2 start");
                t1.join(100);

                t1.join();
                System.out.println("t2 end");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });

        t1.start();
        t2.start();

        Thread.sleep(20);
        System.out.println(STR."t2 state: \{t2.getState()}");

        Thread.sleep(100);
        System.out.println(STR."t2 state: \{t2.getState()}");
    }
}
