Created
November 22, 2014 15:40
-
-
Save sreeprasad/d9f0e512eab485b5ac41 to your computer and use it in GitHub Desktop.
Call join() method of a thread after it has been started
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 ThreadJoin{ | |
| public static void main(String[] args) { | |
| Thread t = new Thread(ThreadJoin::print); | |
| t.start(); | |
| try{ | |
| t.join(); | |
| }catch(InterruptedException e){ | |
| System.out.println(e); | |
| } | |
| System.out.println("I am done"); | |
| } | |
| public static void print(){ | |
| for(int i=0;i<5;i++){ | |
| try{ | |
| System.out.println(i); | |
| Thread.sleep(1000); | |
| }catch(InterruptedException e){ | |
| System.out.println(e); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment