Created
September 25, 2021 07:49
-
-
Save smadil997/55a604e9d528ef5ad334084d9361bc92 to your computer and use it in GitHub Desktop.
How join method work in multi thread
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
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