Skip to content

Instantly share code, notes, and snippets.

@surabhisuman
Created April 2, 2023 12:46
Show Gist options
  • Save surabhisuman/2889e032278b80b82de5a4e89b9feaff to your computer and use it in GitHub Desktop.
Save surabhisuman/2889e032278b80b82de5a4e89b9feaff to your computer and use it in GitHub Desktop.
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