Skip to content

Instantly share code, notes, and snippets.

@sreeprasad
Created November 22, 2014 15:40
Show Gist options
  • Select an option

  • Save sreeprasad/d9f0e512eab485b5ac41 to your computer and use it in GitHub Desktop.

Select an option

Save sreeprasad/d9f0e512eab485b5ac41 to your computer and use it in GitHub Desktop.
Call join() method of a thread after it has been started
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