Java2016. 7. 1. 22:18
class WaitingThread implements Runnable {
Thread thread;
boolean isRun = false;
boolean isWait = false;
public WaitingThread(){}

public void startThread(){
isRun = true;
isWait = false;
if(thread != null) {
     thread = new Thread(this);
thread.start();
}else {
synchronized(thread){
thread.notify();
}
}
}

public void stopThread(){
isRun = false;
if(thread != null){
synchronized(thread){
thread.interrupt();
}
thread = null;
}

}
public void setWait(){
isWait = true;
}
public void waitThread(){
if(thread != null){
synchronized(thread){
try{
thread.wait();
}catch(Exception e){}
}
}
}
public void run(){
while(isRun){
working();
if(isWait) waitThread();
}
}
public void working(){

}

}



Posted by idwook