Advertisement
Guest User

Untitled

a guest
Aug 16th, 2012
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1.     private final Object LOCK = new Object();
  2.     private boolean pauseThreadFlag = false;
  3.  
  4.     private void checkForPause() throws InterruptedException
  5.     {
  6.         if(pauseThreadFlag)
  7.         {
  8.             if(this.getState().equals(Thread.State.RUNNABLE))
  9.             {
  10.                 synchronized(LOCK)
  11.                 {
  12.                     LOCK.wait();
  13.                     pauseThreadFlag = false;
  14.                 }
  15.             }
  16.         }
  17.     }
  18.    
  19.     public void pauseThread()
  20.     {
  21.         pauseThreadFlag = true;
  22.     }
  23.    
  24.     public void resumeThread()
  25.     {
  26.         if(this.getState().equals(Thread.State.WAITING))
  27.         {
  28.             synchronized(LOCK)
  29.             {
  30.                 LOCK.notify();
  31.                 pauseThreadFlag = false;
  32.             }
  33.         }
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement