java.util.concurrent.atomic.AtomicBoolean#wait()源码实例Demo

下面列出了java.util.concurrent.atomic.AtomicBoolean#wait() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: FastAsyncWorldedit   文件: TaskManager.java
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);
    }
}
 
源代码2 项目: hottub   文件: Util.java
public static void waitForConditionEx(final AtomicBoolean condition)
throws InterruptedException
  {
      synchronized (condition) {
          while (!condition.get()) {
              condition.wait();
          }
      }
  }
 
源代码3 项目: jdk8u-dev-jdk   文件: Util.java
public static void waitForConditionEx(final AtomicBoolean condition)
throws InterruptedException
  {
      synchronized (condition) {
          while (!condition.get()) {
              condition.wait();
          }
      }
  }
 
源代码4 项目: openjdk-8-source   文件: Util.java
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();
  }
 
源代码5 项目: jdk8u-jdk   文件: TestAlwaysOnTopBeforeShow.java
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");
    }
}
 
源代码6 项目: openjdk-8   文件: Util.java
public static void waitForConditionEx(final AtomicBoolean condition)
throws InterruptedException
  {
      synchronized (condition) {
          while (!condition.get()) {
              condition.wait();
          }
      }
  }
 
源代码7 项目: jdk8u-jdk   文件: Util.java
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();
  }
 
源代码8 项目: TencentKona-8   文件: Util.java
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();
  }
 
源代码9 项目: jdk8u-dev-jdk   文件: Util.java
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();
  }
 
源代码10 项目: tez   文件: TestPreemption.java
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();
  }     
}
 
源代码11 项目: openjdk-jdk9   文件: Util.java
public static void waitForConditionEx(final AtomicBoolean condition)
throws InterruptedException
  {
      synchronized (condition) {
          while (!condition.get()) {
              condition.wait();
          }
      }
  }
 
源代码12 项目: jdk8u60   文件: TestAlwaysOnTopBeforeShow.java
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");
    }
}
 
源代码13 项目: openjdk-jdk8u   文件: Util.java
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();
  }
 
源代码14 项目: openjdk-jdk8u   文件: Util.java
public static void waitForConditionEx(final AtomicBoolean condition)
throws InterruptedException
  {
      synchronized (condition) {
          while (!condition.get()) {
              condition.wait();
          }
      }
  }
 
源代码15 项目: openjdk-jdk9   文件: Util.java
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();
  }
 
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");
    }
}
 
源代码17 项目: flink   文件: IOManagerAsyncTest.java
@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());
	}
}
 
源代码18 项目: pentaho-kettle   文件: BaseStepTest.java
@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();
  }
}
 
源代码19 项目: incubator-retired-blur   文件: TableDisplay.java
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();
    }
  }
 
源代码20 项目: hbase   文件: OpenRegionHandler.java
/**
 * 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);
}