I have a Thread.sleep(100) line in my program. I want to interrupt the Thread.sleep if the mouse is clicked. What code would I write to do that?
            Asked
            
        
        
            Active
            
        
            Viewed 116 times
        
    1 Answers
1
            
            
        Basically - don't. This is one of the reasons why Thread.sleep is discouraged. You should change it to a BlockingQueue.poll
// Thread.sleep(100);
blockingQueue.poll(100, TimeUnit.MILLISECONDS);
now you can stop the pause by pushing something into the blockingqueue at the other end.
You may even discover that you can increase the timeout too.
 
    
    
        OldCurmudgeon
        
- 64,482
- 16
- 119
- 213
