Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 0.60 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Thread.sleep() in a while loop
  2. String state = get state via RPC call
  3. while (!state.equals("complete")) {
  4.     Thread.sleep(10000); // Wait 10 seconds
  5.     state = {update state via RPC call}
  6. }
  7.        
  8. public class Foo{
  9.   private Lock lock;
  10.   private Condition c1;
  11.   private Condition c2;
  12.  
  13.   public Foo()
  14.   {
  15.     lock = new SimpleLock();
  16.     c1 = lock.newCondition();
  17.     c2 = lock.newCondition();
  18.     ...
  19.   }
  20.  
  21.   public void doIt()
  22.   {
  23.     try{
  24.       lock.lock();
  25.       ...
  26.       while(...){
  27.         c1.awaitUninterruptibly();
  28.       }
  29.       ...
  30.       c2.signal();
  31.     }
  32.     finally{
  33.       lock.unlock();
  34.     }
  35.   }
  36. }