Example usage for java.lang Thread join

List of usage examples for java.lang Thread join

Introduction

In this page you can find the example usage for java.lang Thread join.

Prototype

public final synchronized void join(long millis, int nanos) throws InterruptedException 

Source Link

Document

Waits at most millis milliseconds plus nanos nanoseconds for this thread to die.

Usage

From source file:Main.java

public static void main(String args[]) throws Exception {

    Thread t = new Thread(new ThreadDemo());
    t.start();/*from  w  w w.j  av  a  2 s.c  o  m*/

    t.join(2000, 500);
    //after waiting for 2000 milliseconds plus 500 nanoseconds ...
    System.out.print(t.getName());
    System.out.println(", status = " + t.isAlive());
}

From source file:Main.java

public static void join(Thread thread, long millis, int nanos) {
    try {/*ww  w.j  a va 2  s  .  com*/
        thread.join(millis, nanos);
    } catch (InterruptedException inex) {
        // ignore
    }
}

From source file:Main.java

/**
 * Causes the current Thread to join with the specified Thread.  If the current Thread is interrupted while waiting
 * for the specified Thread, then the current Threads interrupt bit will be set and this method will return false.
 * Otherwise, the current Thread will wait on the specified Thread until it dies, or until the time period has expired
 * and then the method will return true.
 * //from w  w  w .  j ava  2  s  .c  o m
 * @param thread the Thread that the current Thread (caller) will join.
 * @param milliseconds the number of milliseconds the current Thread will wait during the join operation.  If the
 * number of milliseconds specified is 0, then the current Thread will wait until the specified Thread dies, or the
 * current Thread is interrupted.
 * @param nanoseconds the number of nanoseconds in addition to the milliseconds the current Thread will wait during
 * the join operation.
 * @return a boolean condition indicating if the current Thread successfully joined the specified Thread without being
 * interrupted.
 * @see java.lang.Thread#join(long, int)
 * @see java.lang.Thread#interrupt()
 */
public static boolean join(final Thread thread, final long milliseconds, final int nanoseconds) {
    try {
        thread.join(milliseconds, nanoseconds);
        return true;
    } catch (InterruptedException ignore) {
        Thread.currentThread().interrupt();
        return false;
    }
}