Java Code Examples for java.util.concurrent.atomic.AtomicBoolean#wait()

The following examples show how to use java.util.concurrent.atomic.AtomicBoolean#wait() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public void wait(AtomicBoolean running, int timout) {
    try {
        long start = System.currentTimeMillis();
        synchronized (running) {
            while (running.get()) {
                running.wait(timout);
                if (running.get() && System.currentTimeMillis() - start > Settings.IMP.QUEUE.DISCARD_AFTER_MS) {
                    new RuntimeException("FAWE is taking a long time to execute a task (might just be a symptom): ").printStackTrace();
                    Fawe.debug("For full debug information use: /fawe threads");
                }
            }
        }
    } catch (InterruptedException e) {
        MainUtil.handleError(e);
    }
}
 
Example 2
Source Project: hottub   File: Util.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void waitForConditionEx(final AtomicBoolean condition)
throws InterruptedException
  {
      synchronized (condition) {
          while (!condition.get()) {
              condition.wait();
          }
      }
  }
 
Example 3
Source Project: jdk8u-dev-jdk   File: Util.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void waitForConditionEx(final AtomicBoolean condition)
throws InterruptedException
  {
      synchronized (condition) {
          while (!condition.get()) {
              condition.wait();
          }
      }
  }
 
Example 4
public static boolean waitForConditionEx(final AtomicBoolean condition, long timeout)
throws InterruptedException
  {
      synchronized (condition) {
          long startTime = System.currentTimeMillis();
          while (!condition.get()) {
              condition.wait(timeout);
              if (System.currentTimeMillis() - startTime >= timeout ) {
                  break;
              }
          }
      }
      return condition.get();
  }
 
Example 5
static void waitFocused(Window w, AtomicBoolean b) {
    try {
        synchronized(b) {
            if (w.isFocusOwner()) {
                return;
            }
            b.wait(3000);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    if (!w.isFocusOwner()) {
        throw new RuntimeException("Can't make " + w + " focus owner");
    }
}
 
Example 6
Source Project: openjdk-8   File: Util.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void waitForConditionEx(final AtomicBoolean condition)
throws InterruptedException
  {
      synchronized (condition) {
          while (!condition.get()) {
              condition.wait();
          }
      }
  }
 
Example 7
Source Project: jdk8u-jdk   File: Util.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static boolean waitForConditionEx(final AtomicBoolean condition, long timeout)
throws InterruptedException
  {
      synchronized (condition) {
          long startTime = System.currentTimeMillis();
          while (!condition.get()) {
              condition.wait(timeout);
              if (System.currentTimeMillis() - startTime >= timeout ) {
                  break;
              }
          }
      }
      return condition.get();
  }
 
Example 8
Source Project: TencentKona-8   File: Util.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static boolean waitForConditionEx(final AtomicBoolean condition, long timeout)
throws InterruptedException
  {
      synchronized (condition) {
          long startTime = System.currentTimeMillis();
          while (!condition.get()) {
              condition.wait(timeout);
              if (System.currentTimeMillis() - startTime >= timeout ) {
                  break;
              }
          }
      }
      return condition.get();
  }
 
Example 9
Source Project: jdk8u-dev-jdk   File: Util.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static boolean waitForConditionEx(final AtomicBoolean condition, long timeout)
throws InterruptedException
  {
      synchronized (condition) {
          long startTime = System.currentTimeMillis();
          while (!condition.get()) {
              condition.wait(timeout);
              if (System.currentTimeMillis() - startTime >= timeout ) {
                  break;
              }
          }
      }
      return condition.get();
  }
 
Example 10
Source Project: tez   File: TestPreemption.java    License: Apache License 2.0 5 votes vote down vote up
void syncWithMockAppLauncher(boolean allowScheduling, AtomicBoolean mockAppLauncherGoFlag, 
    MockTezClient tezClient) throws Exception {
  synchronized (mockAppLauncherGoFlag) {
    while (!mockAppLauncherGoFlag.get()) {
      mockAppLauncherGoFlag.wait();
    }
    mockApp = tezClient.getLocalClient().getMockApp();
    mockLauncher = mockApp.getContainerLauncher();
    mockLauncher.startScheduling(allowScheduling);
    mockAppLauncherGoFlag.notify();
  }     
}
 
Example 11
Source Project: openjdk-jdk9   File: Util.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void waitForConditionEx(final AtomicBoolean condition)
throws InterruptedException
  {
      synchronized (condition) {
          while (!condition.get()) {
              condition.wait();
          }
      }
  }
 
Example 12
static void waitFocused(Window w, AtomicBoolean b) {
    try {
        synchronized(b) {
            if (w.isFocusOwner()) {
                return;
            }
            b.wait(3000);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    if (!w.isFocusOwner()) {
        throw new RuntimeException("Can't make " + w + " focus owner");
    }
}
 
Example 13
Source Project: openjdk-jdk8u   File: Util.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static boolean waitForConditionEx(final AtomicBoolean condition, long timeout)
throws InterruptedException
  {
      synchronized (condition) {
          long startTime = System.currentTimeMillis();
          while (!condition.get()) {
              condition.wait(timeout);
              if (System.currentTimeMillis() - startTime >= timeout ) {
                  break;
              }
          }
      }
      return condition.get();
  }
 
Example 14
Source Project: openjdk-jdk8u   File: Util.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void waitForConditionEx(final AtomicBoolean condition)
throws InterruptedException
  {
      synchronized (condition) {
          while (!condition.get()) {
              condition.wait();
          }
      }
  }
 
Example 15
Source Project: openjdk-jdk9   File: Util.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static boolean waitForConditionEx(final AtomicBoolean condition, long timeout)
throws InterruptedException
  {
      synchronized (condition) {
          long startTime = System.currentTimeMillis();
          while (!condition.get()) {
              condition.wait(timeout);
              if (System.currentTimeMillis() - startTime >= timeout ) {
                  break;
              }
          }
      }
      return condition.get();
  }
 
Example 16
static void waitFocused(Window w, AtomicBoolean b) {
    try {
        synchronized(b) {
            if (w.isFocusOwner()) {
                return;
            }
            b.wait(3000);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    if (!w.isFocusOwner()) {
        throw new RuntimeException("Can't make " + w + " focus owner");
    }
}
 
Example 17
Source Project: flink   File: IOManagerAsyncTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testExceptionPropagationReader() {
	try {
		// use atomic boolean as a boolean reference
		final AtomicBoolean handlerCalled = new AtomicBoolean();
		final AtomicBoolean exceptionForwarded = new AtomicBoolean();
		
		ReadRequest req = new ReadRequest() {
			
			@Override
			public void requestDone(IOException ioex) {
				if (ioex instanceof TestIOException) {
					exceptionForwarded.set(true);
				}
				
				synchronized (handlerCalled) {
					handlerCalled.set(true);
					handlerCalled.notifyAll();
				}
			}
			
			@Override
			public void read() throws IOException {
				throw new TestIOException();
			}
		};
		
		
		// test the read queue
		RequestQueue<ReadRequest> rq = ioManager.getReadRequestQueue(ioManager.createChannel());
		rq.add(req);

		// wait until the asynchronous request has been handled
		synchronized (handlerCalled) {
			while (!handlerCalled.get()) {
				handlerCalled.wait();
			}
		}
		
		assertTrue(exceptionForwarded.get());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 18
Source Project: pentaho-kettle   File: BaseStepTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testStepListenersConcurrentModification() throws InterruptedException {
  // Create a base step
  final BaseStep baseStep =
    new BaseStep( mockHelper.stepMeta, mockHelper.stepDataInterface, 0, mockHelper.transMeta, mockHelper.trans );

  // Create thread to dynamically add listeners
  final AtomicBoolean done = new AtomicBoolean( false );
  Thread addListeners = new Thread() {
    @Override
    public void run() {
      while ( !done.get() ) {
        baseStep.addStepListener( mock( StepListener.class ) );
        synchronized ( done ) {
          done.notify();
        }
      }
    }
  };

  // Mark start and stop while listeners are being added
  try {
    addListeners.start();

    // Allow a few listeners to be added
    synchronized ( done ) {
      while ( baseStep.getStepListeners().size() < 20 ) {
        done.wait();
      }
    }

    baseStep.markStart();

    // Allow more listeners to be added
    synchronized ( done ) {
      while ( baseStep.getStepListeners().size() < 100 ) {
        done.wait();
      }
    }

    baseStep.markStop();

  } finally {
    // Close addListeners thread
    done.set( true );
    addListeners.join();
  }
}
 
Example 19
public static void main(String[] args) throws IOException, InterruptedException {

    // System.out.println("\u001B[1mfoo\u001B[[email protected]\u001B[[email protected]\u001B[0m>");

    // \u001B[0m normal
    // \u001B[33m yellow

    // System.out.println("\u001B[33mCOLUMN\u001B[0mnormal");
    //
    // for (int i = 0; i < 100; i++) {
    // System.out.println("\u001B[0m" + i + "\u001B[" + i + "mfoo");
    // }

    ConsoleReader reader = new ConsoleReader();
    TableDisplay tableDisplay = new TableDisplay(reader);
    tableDisplay.setSeperator("|");
    // Random random = new Random();
    int maxX = 20;
    int maxY = 100;
    tableDisplay.setHeader(0, "");
    for (int i = 1; i < maxX; i++) {
      tableDisplay.setHeader(i, "col-" + i);
    }

    for (int i = 0; i < maxY; i++) {
      tableDisplay.set(0, i, i);
    }

    final AtomicBoolean running = new AtomicBoolean(true);

    tableDisplay.addKeyHook(new Runnable() {
      @Override
      public void run() {
        synchronized (running) {
          running.set(false);
          running.notifyAll();
        }
      }
    }, 'q');

    try {
      // int i = 0;
      // while (true) {
      // if (i >= 100000) {
      // i = 0;
      // }
      // tableDisplay.set(random.nextInt(maxX) + 1, random.nextInt(maxY),
      // random.nextLong());
      // Thread.sleep(3000);
      // i++;
      // }
      for (int x = 0; x < maxX; x++) {
        for (int y = 0; y < maxY; y++) {
          if (x == 7 && y == 7) {
            tableDisplay.set(x, y, highlight(x + "," + y));
          } else {
            tableDisplay.set(x, y, x + "," + y);
          }
        }
      }
      while (running.get()) {
        synchronized (running) {
          running.wait(1000);
        }
      }
    } finally {
      tableDisplay.close();
    }
  }
 
Example 20
Source Project: hbase   File: OpenRegionHandler.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Update ZK or META.  This can take a while if for example the
 * hbase:meta is not available -- if server hosting hbase:meta crashed and we are
 * waiting on it to come back -- so run in a thread and keep updating znode
 * state meantime so master doesn't timeout our region-in-transition.
 * Caller must cleanup region if this fails.
 */
private boolean updateMeta(final HRegion r, long masterSystemTime) {
  if (this.server.isStopped() || this.rsServices.isStopping()) {
    return false;
  }
  // Object we do wait/notify on.  Make it boolean.  If set, we're done.
  // Else, wait.
  final AtomicBoolean signaller = new AtomicBoolean(false);
  PostOpenDeployTasksThread t = new PostOpenDeployTasksThread(r,
    this.server, this.rsServices, signaller, masterSystemTime);
  t.start();
  // Post open deploy task:
  //   meta => update meta location in ZK
  //   other region => update meta
  while (!signaller.get() && t.isAlive() && !this.server.isStopped() &&
      !this.rsServices.isStopping() && isRegionStillOpening()) {
    synchronized (signaller) {
      try {
        // Wait for 10 seconds, so that server shutdown
        // won't take too long if this thread happens to run.
        if (!signaller.get()) signaller.wait(10000);
      } catch (InterruptedException e) {
        // Go to the loop check.
      }
    }
  }
  // Is thread still alive?  We may have left above loop because server is
  // stopping or we timed out the edit.  Is so, interrupt it.
  if (t.isAlive()) {
    if (!signaller.get()) {
      // Thread still running; interrupt
      LOG.debug("Interrupting thread " + t);
      t.interrupt();
    }
    try {
      t.join();
    } catch (InterruptedException ie) {
      LOG.warn("Interrupted joining " +
        r.getRegionInfo().getRegionNameAsString(), ie);
      Thread.currentThread().interrupt();
    }
  }

  // Was there an exception opening the region?  This should trigger on
  // InterruptedException too.  If so, we failed.
  return (!Thread.interrupted() && t.getException() == null);
}