Skip to content

Instantly share code, notes, and snippets.

@Teino1978-Corp
Created November 17, 2015 07:19
Show Gist options
  • Save Teino1978-Corp/4c8936b1dce8c2f67a4a to your computer and use it in GitHub Desktop.
Save Teino1978-Corp/4c8936b1dce8c2f67a4a to your computer and use it in GitHub Desktop.
final boolean isAlive (): call this method when thread is still alive, it will return true, otherwise return false
public class DemoJoin {
public static void main (String args []) {
NewThread ob [] = {new NewThread ("One"), new NewThread ("Two"), new NewThread ("Three")};
for (int i = 0; i <3; i ++)
System.out.println ("Thread" + ob [i] .name + "is alive:" + ob [i] .t.isAlive ());
try {
System.out.println ("Waiting for threads to finish.");
ob [0] .t.join ();
ob [1] .t.join ();
ob [2] .t.join ();
} Catch (InterruptedException e) {
// TODO: handle exception
System.out.println ("Main thread Interrupted");
}
for (int i = 0; i <3; i ++)
System.out.println ("Thread" + ob [i] .name + "is alive:" + ob [i] .t.isAlive ());
System.out.println ("Main thread exiting.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment