예제 #1
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();
  }
예제 #2
0
  public static void main(String[] args) throws Exception {
    final Runner runner = new Runner();
    Thread t1 =
        new Thread(
            new Runnable() {
              public void run() {
                try {
                  runner.firstThread();
                } catch (InterruptedException ignored) {
                }
              }
            });

    Thread t2 =
        new Thread(
            new Runnable() {
              public void run() {
                try {
                  runner.secondThread();
                } catch (InterruptedException ignored) {
                }
              }
            });

    t1.start();
    t2.start();
    t1.join();
    t2.join();
    runner.finished();
  }