Control a thread from outsideTag(s): Thread
public class TT extends Thread {
static final int RUN = 0;
static final int SUSPEND = 1;
static final int STOP = 2;
private int state = RUN;
public synchronized void setState(int s) {
state = s;
if (s == RUN) notify();
}
private boolean boolean checkState() {
while (state == SUSPEND) {
try {
wait();
}
catch (Exception e) {}
}
if (state == STOP)
return false;
return true;
}
public void run() {
while true {
doSomething();
if (!checkState())
break;
}
}
mail_outline
Send comment, question or suggestion to howto@rgagnon.com
Send comment, question or suggestion to howto@rgagnon.com