Created
November 17, 2015 07:19
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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