Best Method to pause a Thread?
问题 I have a Runnable class which performs an operation continuously in its run method using an infinite while loop. Sometimes a user might want to pause/resume the operation. What is the best method to pause the Thread. I have two thoughts: FIRST class Foo extends Runnable { @Override public void run() { while(true) { if(pauseFlag) try{ Thread.sleep(); } catch(InterrruptedException ie) {//...} } } SECOND class Foo extends Runnable { @Override public void run() { while(true) { //pause if user