Java tutorial
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(); } }