Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.concurrent.CountDownLatch;

public class Main {
    static CountDownLatch cdl;

    public static void main(String... s) {
        cdl = new CountDownLatch(1);
        Thread a = new Thread(() -> {
            System.out.println("started a");
            try {
                Thread.sleep(4000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            cdl.countDown();
            System.out.println("stoped a");
        });
        Thread b = new Thread(() -> {
            System.out.println("started b");
            System.out.println("wait a");
            try {
                cdl.await();
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println("stoped b");
        });
        b.start();
        a.start();
    }
}