Example usage for java.util.concurrent CountDownLatch CountDownLatch

List of usage examples for java.util.concurrent CountDownLatch CountDownLatch

Introduction

In this page you can find the example usage for java.util.concurrent CountDownLatch CountDownLatch.

Prototype

public CountDownLatch(int count) 

Source Link

Document

Constructs a CountDownLatch initialized with the given count.

Usage

From source file:Main.java

public static void main(String args[]) {
    CountDownLatch cdl = new CountDownLatch(5);
    new MyThread(cdl);

    try {/*from w w  w.ja v a  2  s.  c o  m*/
        cdl.await();
    } catch (InterruptedException exc) {
        System.out.println(exc);
    }
    System.out.println("Done");
}

From source file:Main.java

public static void main(String args[]) {
    CountDownLatch cdl = new CountDownLatch(5);
    System.out.println(cdl.getCount());
    new MyThread(cdl);

    try {//from ww w .  j a  v  a2  s. c om
        cdl.await();
    } catch (InterruptedException exc) {
        System.out.println(exc);
    }
    System.out.println("Done");
}

From source file:Main.java

public static void main(String... s) {
    cdl = new CountDownLatch(1);
    Thread a = new Thread(() -> {
        System.out.println("started a");
        try {//  w  ww. j a va2 s  .c om
            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();
}

From source file:Main.java

public static void main(String args[]) {
    CountDownLatch cdl = new CountDownLatch(5);
    System.out.println(cdl.getCount());
    new MyThread(cdl);

    try {/*from   w  w  w.j  a  va 2  s . c om*/
        cdl.await(100, TimeUnit.SECONDS);
    } catch (InterruptedException exc) {
        System.out.println(exc);
    }
    System.out.println("Done");
}

From source file:Main.java

public static void main(String args[]) {
    CountDownLatch cdl = new CountDownLatch(5);
    System.out.println(cdl.getCount());
    new MyThread(cdl);

    try {/*w  ww .j ava2 s  .co m*/
        cdl.await(100, TimeUnit.SECONDS);
    } catch (InterruptedException exc) {
        System.out.println(exc);
    }
    System.out.println(cdl.toString());
}

From source file:Main.java

public static void main(String[] args) {
    CountDownLatch latch = new CountDownLatch(1);
    for (int threadNo = 0; threadNo < 1000; threadNo++) {
        Runnable t = new Test(latch);
        new Thread(t).start();
    }/*from  w  ww .  j  a  v  a2 s . c o  m*/
    try {
        latch.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    System.out.println("done");
}

From source file:Main.java

public static void main(String[] args) {
    Object obj1 = new Object();
    Object obj2 = new Object();
    CountDownLatch latch = new CountDownLatch(2);

    new Locker(obj1, obj2, latch).start();
    new Locker(obj2, obj1, latch).start();
}

From source file:SimpExec.java

public static void main(String args[]) {
    CountDownLatch cdl = new CountDownLatch(5);
    CountDownLatch cdl2 = new CountDownLatch(5);
    CountDownLatch cdl3 = new CountDownLatch(5);
    CountDownLatch cdl4 = new CountDownLatch(5);
    ExecutorService es = Executors.newFixedThreadPool(2);

    es.execute(new MyThread(cdl, "A"));
    es.execute(new MyThread(cdl2, "B"));
    es.execute(new MyThread(cdl3, "C"));
    es.execute(new MyThread(cdl4, "D"));

    try {/*from  ww w  .  j a va  2s. c o m*/
        cdl.await();
        cdl2.await();
        cdl3.await();
        cdl4.await();
    } catch (InterruptedException exc) {
        System.out.println(exc);
    }

    es.shutdown();
}

From source file:com.dianping.dpsf.other.echo.EchoServer.java

/**
 * @param args//from w  w  w.j a  v a2 s .  c o m
 * @throws InterruptedException 
 */
public static void main(String[] args) throws InterruptedException {
    Thread.currentThread().setName("=============EchoSerer1============");
    ApplicationContext ctx = new ClassPathXmlApplicationContext("echo-server.xml");
    if (args.length == 0) { //stand alone start
        CountDownLatch latch = new CountDownLatch(1);
        latch.await();
    }
}

From source file:com.dianping.dpsf.other.echo.EchoServer2.java

/**
 * @param args//from  w  w  w .  j av  a  2  s .  c  o  m
 * @throws InterruptedException 
 */
public static void main(String[] args) throws InterruptedException {
    Thread.currentThread().setName("=============EchoSerer2============");
    ApplicationContext ctx = new ClassPathXmlApplicationContext("echo-server2.xml");
    if (args.length == 0) { //stand alone start
        CountDownLatch latch = new CountDownLatch(1);
        latch.await();
    }
}