Skip to content

Instantly share code, notes, and snippets.

@nihat-js
Last active February 7, 2024 17:01
Show Gist options
  • Save nihat-js/8d49735f9c1f57fa3be22140c67abb1c to your computer and use it in GitHub Desktop.
Save nihat-js/8d49735f9c1f57fa3be22140c67abb1c to your computer and use it in GitHub Desktop.
public class ZombieThreadTester {
public static void main(String[] args) {
Thread[] threads = new Thread[100];
for (int i = 0; i < 100; i++) {
threads[i] = new Thread(new MyRunnable(i));
}
for (int i = 0; i < 100; i++) {
threads[i].start();
}
}
}
class MyRunnable implements Runnable {
private int index;
MyRunnable(int index) {
this.index = index;
}
@Override
public void run() {
System.out.println("running" + index);
}
}
public class ZombieThreadTester {
public static void main(String[] args) {
Thread z1 = new Thread(new ZombieThread("WINDOWS"));
Thread z2 = new Thread(new ZombieThread("LINUX"));
Thread z3 = new Thread(new ZombieThread("UNIX"));
Thread z4 = new Thread(new ZombieThread("UNIX"));
System.out.println("Active Count"+Thread.activeCount());
z1.run();
z2.run();
z3.run();
z4.run();
System.out.println("Active Count"+Thread.activeCount());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment