Created
October 24, 2018 16:34
-
-
Save finnkvan/baa731882995e178ce5cc76f18218ab9 to your computer and use it in GitHub Desktop.
Example of thread join
This file contains 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
package com.pivincii; | |
public class Main { | |
public static void main(String[] args) throws InterruptedException { | |
System.out.println("Start Main Thread"); | |
Thread t1 = new Thread(new Runnable() { | |
@Override | |
public void run() { | |
System.out.println("Start Thread 1"); | |
try { | |
Thread.sleep(5000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
System.out.println("Finish Thread 1"); | |
} | |
}); | |
t1.start(); | |
t1.join(); | |
System.out.println("Finish Main Thread"); | |
} | |
/** | |
Output log: | |
Start Main Thread | |
Start Thread 1 | |
Finish Thread 1 | |
Finish Main Thread | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment