예제 #1
1
  public static void main(String[] args) throws InterruptedException {
    final Runner runner = new Runner();

    Thread thread1 =
        new Thread(
            () -> {
              try {
                runner.firstThread();
              } catch (InterruptedException e) {
              }
            });

    Thread thread2 =
        new Thread(
            () -> {
              try {
                runner.secondThread();
              } catch (InterruptedException e) {
              }
            });

    thread1.start();
    thread2.start();

    thread1.join();
    thread2.join();

    runner.printCount();
  }
예제 #2
0
  public static void main(String[] args) throws InterruptedException {
    final Runner runner = new Runner();

    Thread t1 =
        new Thread(
            () -> {
              try {
                runner.firstThread();
              } catch (InterruptedException e) {
                e.printStackTrace();
              }
            },
            "first");

    Thread t2 =
        new Thread(
            () -> {
              try {
                runner.secondThread();
              } catch (InterruptedException e) {
                e.printStackTrace();
              }
            },
            "second");

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

    t1.join();
    t2.join();

    runner.finished();
  }