Skip to content

Instantly share code, notes, and snippets.

@smadil997
Created September 25, 2021 07:49
Show Gist options
  • Save smadil997/55a604e9d528ef5ad334084d9361bc92 to your computer and use it in GitHub Desktop.
Save smadil997/55a604e9d528ef5ad334084d9361bc92 to your computer and use it in GitHub Desktop.
How join method work in multi thread
package pckMain;
public class ThreadExampleWithRunnableNormal {
public static void main(String[] args) {
Thread threadOne = new Thread(new MainThreadClass(), "Thread One");
Thread threadTwo = new Thread(new MainThreadClass(), "Thread Two");
Thread threadThree = new Thread(new MainThreadClass(), "Thread Three");
threadOne.start();
threadTwo.start();
threadThree.start();
System.out.println("All threads are dead/complete");
}
}
class MainThreadClass implements Runnable{
@Override
public void run() {
System.out.println("Started thread :::"+Thread.currentThread().getName());
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Ended thread :::"+Thread.currentThread().getName());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment