Last active
February 7, 2024 17:01
-
-
Save nihat-js/8d49735f9c1f57fa3be22140c67abb1c to your computer and use it in GitHub Desktop.
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
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); | |
} | |
} | |
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
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