Created
April 2, 2023 12:46
-
-
Save surabhisuman/2889e032278b80b82de5a4e89b9feaff to your computer and use it in GitHub Desktop.
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
import java.util.ArrayList; | |
import java.util.List; | |
public class JavaMultithreading { | |
private static class DoSomething implements Runnable { | |
@Override | |
public void run() { | |
System.out.println("\n Thread is executing " + Thread.currentThread().getName()); | |
} | |
} | |
public static void main(String[] args) { | |
List<Thread> threads = new ArrayList<>(); | |
for (int i = 1; i <= 10; i++ ) { | |
String threadName = i + "th thread"; | |
Thread thread = new Thread(new DoSomething(), threadName); | |
threads.add(thread); | |
} | |
for (Thread thread : threads) { thread.start(); } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment