 | Thread Management
 | sleep - give up execution time slice for a fixed amount
of time |
 | yield - give any other running thread its slice of
execution time |
 | //Dangerous and deprecated |
 | suspend - make a running thread temporarily stop |
 | resume - make a suspended thread running again |
 | stop - permanently stop a thread |
PingPong.java
class PingPong extends Thread {
String word;
int delay;
PingPong(String whatToSay, int delayInterval) {
word = whatToSay;
delay = delayInterval;
}
public void run() {
try {
for (;;) {
System.out.print(word + " ");
sleep(delay); //wait for delay ms
}
} catch (InterruptedException e) {
return; //end on any error
}
}
public static void main(String[] args) {
new PingPong("ping", 33).start(); //repeat 1/30 sec
new PingPong("PONG", 100).start(); //repeat 1/10 sec
}
}
|