How to pause execution of some Thread. I have Thread t and I have two buttons, PAUSE and CONTINUE. On pause I need to pause thread execution and on continue to thread start
You can try this:
private boolean isPaused = false; public synchronized void pause(){ isPaused = true; } public synchronized void play(){ isPaused = false; notyfyAll(); } public synchronized void look(){ while(isPaused) wait(); } public void run(){ while(true){ look(); //your code }