Java Thread.join(long millis, int nanos)
Syntax
Thread.join(long millis, int nanos) has the following syntax.
public final void join(long millis, int nanos) throws InterruptedException
Example
In the following code shows how to use Thread.join(long millis, int nanos) method.
public class Main {
//w w w .j av a 2s.c om
public static void main(String args[]) throws Exception {
Thread t = new Thread(new ThreadDemo());
t.start();
t.join(2000, 500);
//after waiting for 2000 milliseconds plus 500 nanoseconds ...
System.out.print(t.getName());
System.out.println(", status = " + t.isAlive());
}
}
class ThreadDemo implements Runnable {
public void run() {
Thread t = Thread.currentThread();
System.out.print(t.getName());
// checks if this thread is alive
System.out.println(", status = " + t.isAlive());
}
}