Java Thread Suspend Example
Chapter:
Thread
Last Updated:
10-09-2016 06:05:40 UTC
Program:
/* ............... START ............... */
public class JavaThreadSuspend extends Thread {
private int countDown = 5;
private static int threadCount = 0;
public JavaThreadSuspend() {
super("" + ++threadCount);
start();
}
public String toString() {
return "#" + getName() + ": " + countDown;
}
public void run() {
while (true) {
System.out.println(this);
if (--countDown == 0)
return;
try {
sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
public static void main(String[] args) throws InterruptedException {
for (int i = 0; i < 5; i++)
new JavaThreadSuspend().join();
System.out.println("The thread has been suspened.");
}
}
/* ............... END ............... */
Output
The thread has been suspened.
Tags
Thread Suspend Example, Java, Thread