Skip to content

Instantly share code, notes, and snippets.

@finnkvan
Created October 24, 2018 16:34
Show Gist options
  • Save finnkvan/baa731882995e178ce5cc76f18218ab9 to your computer and use it in GitHub Desktop.
Save finnkvan/baa731882995e178ce5cc76f18218ab9 to your computer and use it in GitHub Desktop.
Example of thread join
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