com.google.common.util.concurrent.Monitor.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中com.google.common.util.concurrent.Monitor.<init>()方法的一些代码示例,展示了Monitor.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Monitor.<init>()方法的具体详情如下:
包路径:com.google.common.util.concurrent.Monitor
类名称:Monitor
方法名:<init>

Monitor.<init>介绍

[英]Creates a monitor with a non-fair (but fast) ordering policy. Equivalent to Monitor(false).
[中]创建具有非公平(但快速)订购策略的监控器。相当于监视器(错误)。

代码示例

代码示例来源:origin: google/guava

public void testGetWaitQueueLengthWithWrongMonitorThrowsIMSE() {
 Monitor monitor1 = new Monitor();
 Monitor monitor2 = new Monitor();
 FlagGuard guard = new FlagGuard(monitor2);
 try {
  monitor1.getWaitQueueLength(guard);
  fail("expected IllegalMonitorStateException");
 } catch (IllegalMonitorStateException expected) {
 }
}

代码示例来源:origin: google/guava

private GeneratedMonitorTest(
  Method method, Scenario scenario, boolean fair, Timeout timeout, Outcome expectedOutcome) {
 super(nameFor(method, scenario, fair, timeout, expectedOutcome));
 this.method = method;
 this.scenario = scenario;
 this.timeout = timeout;
 this.expectedOutcome = expectedOutcome;
 this.monitor = new Monitor(fair);
 this.guard = new FlagGuard(monitor);
 this.tearDownLatch = new CountDownLatch(1);
 this.doingCallLatch = new CountDownLatch(1);
 this.callCompletedLatch = new CountDownLatch(1);
}

代码示例来源:origin: google/guava

public void testHasWaitersWithWrongMonitorThrowsIMSE() {
 Monitor monitor1 = new Monitor();
 Monitor monitor2 = new Monitor();
 FlagGuard guard = new FlagGuard(monitor2);
 try {
  monitor1.hasWaiters(guard);
  fail("expected IllegalMonitorStateException");
 } catch (IllegalMonitorStateException expected) {
 }
}

代码示例来源:origin: google/guava

public void testIsFair() {
 assertTrue(new Monitor(true).isFair());
 assertFalse(new Monitor(false).isFair());
}

代码示例来源:origin: google/guava

public void testLeaveWithoutEnterThrowsIMSE() {
 Monitor monitor = new Monitor();
 try {
  monitor.leave();
  fail("expected IllegalMonitorStateException");
 } catch (IllegalMonitorStateException expected) {
 }
}

代码示例来源:origin: google/guava

@Override
 protected void runTest() throws Throwable {
  Monitor monitor = new Monitor(fair);
  FlagGuard guard = new FlagGuard(monitor);
  Object[] arguments =
    (timed ? new Object[] {guard, 0L, TimeUnit.MILLISECONDS} : new Object[] {guard});
  try {
   method.invoke(monitor, arguments);
   fail("expected IllegalMonitorStateException");
  } catch (InvocationTargetException e) {
   assertEquals(IllegalMonitorStateException.class, e.getTargetException().getClass());
  }
 }
};

代码示例来源:origin: google/guava

@Override
protected final void setUp() throws Exception {
 boolean fair = new Random().nextBoolean();
 monitor = new Monitor(fair);
 tearDownStack.addTearDown(thread1 = new TestThread<>(monitor, "TestThread #1"));
 tearDownStack.addTearDown(thread2 = new TestThread<>(monitor, "TestThread #2"));
}

代码示例来源:origin: google/guava

@Override
protected void runTest() throws Throwable {
 Monitor monitor1 = new Monitor(fair1);
 Monitor monitor2 = new Monitor(fair2);
 FlagGuard guard = new FlagGuard(monitor2);
 Object[] arguments =

代码示例来源:origin: google/guava

@Override
 protected void runTest() throws Throwable {
  Monitor monitor1 = new Monitor(fair1);
  Monitor monitor2 = new Monitor(fair2);
  FlagGuard guard = new FlagGuard(monitor2);
  Object[] arguments =
    (timed ? new Object[] {guard, 0L, TimeUnit.MILLISECONDS} : new Object[] {guard});
  boolean occupyMonitor = isWaitFor(method);
  if (occupyMonitor) {
   // If we don't already occupy the monitor, we'll get an IMSE regardless of the guard (see
   // generateWaitForWhenNotOccupyingTestCase).
   monitor1.enter();
  }
  try {
   method.invoke(monitor1, arguments);
   fail("expected IllegalMonitorStateException");
  } catch (InvocationTargetException e) {
   assertEquals(IllegalMonitorStateException.class, e.getTargetException().getClass());
  } finally {
   if (occupyMonitor) {
    monitor1.leave();
   }
  }
 }
};

代码示例来源:origin: google/guava

/**
 * Generates a test case verifying that calling any waitForXxx method when not occupying the
 * monitor produces an IllegalMonitorStateException.
 */
private static TestCase generateWaitForWhenNotOccupyingTestCase(
  final Method method, final boolean fair) {
 final boolean timed = isTimed(method); // Not going to bother with all timeouts, just 0ms.
 String testName =
   method.getName()
     + (fair ? "(fair)" : "(nonfair)")
     + (timed ? "(0ms)" : "()")
     + "/NotOccupying->IMSE";
 return new TestCase(testName) {
  @Override
  protected void runTest() throws Throwable {
   Monitor monitor = new Monitor(fair);
   FlagGuard guard = new FlagGuard(monitor);
   Object[] arguments =
     (timed ? new Object[] {guard, 0L, TimeUnit.MILLISECONDS} : new Object[] {guard});
   try {
    method.invoke(monitor, arguments);
    fail("expected IllegalMonitorStateException");
   } catch (InvocationTargetException e) {
    assertEquals(IllegalMonitorStateException.class, e.getTargetException().getClass());
   }
  }
 };
}

代码示例来源:origin: google/guava

public void testOccupiedMethods() {
 Monitor monitor = new Monitor();
 verifyOccupiedMethodsInCurrentThread(monitor, false, false, 0);
 verifyOccupiedMethodsInAnotherThread(monitor, false, false, 0);
 monitor.enter();
 try {
  verifyOccupiedMethodsInCurrentThread(monitor, true, true, 1);
  verifyOccupiedMethodsInAnotherThread(monitor, true, false, 0);
  monitor.enter();
  try {
   verifyOccupiedMethodsInCurrentThread(monitor, true, true, 2);
   verifyOccupiedMethodsInAnotherThread(monitor, true, false, 0);
  } finally {
   monitor.leave();
  }
  verifyOccupiedMethodsInCurrentThread(monitor, true, true, 1);
  verifyOccupiedMethodsInAnotherThread(monitor, true, false, 0);
 } finally {
  monitor.leave();
 }
 verifyOccupiedMethodsInCurrentThread(monitor, false, false, 0);
 verifyOccupiedMethodsInAnotherThread(monitor, false, false, 0);
}

代码示例来源:origin: lenskit/lenskit

@Test
public void testAcquireMonitor() {
  Monitor monitor = new Monitor();
  ForkJoinPool.commonPool().invoke(new RecursiveAction() {
    AtomicInteger running = new AtomicInteger();

代码示例来源:origin: org.apache.marmotta/marmotta-commons

@Override
  public Monitor load(Object key) throws Exception {
    return new Monitor();
  }
}

代码示例来源:origin: stackoverflow.com

private final Monitor monitor = new Monitor();
private final Monitor.Guard paused = new Monitor.Guard(monitor) {
  @Override

代码示例来源:origin: com.google.guava/guava-tests

public void testHasWaitersWithWrongMonitorThrowsIMSE() {
 Monitor monitor1 = new Monitor();
 Monitor monitor2 = new Monitor();
 FlagGuard guard = new FlagGuard(monitor2);
 try {
  monitor1.hasWaiters(guard);
  fail("expected IllegalMonitorStateException");
 } catch (IllegalMonitorStateException expected) {
 }
}

代码示例来源:origin: com.google.guava/guava-tests

public void testGetWaitQueueLengthWithWrongMonitorThrowsIMSE() {
 Monitor monitor1 = new Monitor();
 Monitor monitor2 = new Monitor();
 FlagGuard guard = new FlagGuard(monitor2);
 try {
  monitor1.getWaitQueueLength(guard);
  fail("expected IllegalMonitorStateException");
 } catch (IllegalMonitorStateException expected) {
 }
}

代码示例来源:origin: com.google.guava/guava-tests

@Override protected void runTest() throws Throwable {
  Monitor monitor = new Monitor(fair);
  FlagGuard guard = new FlagGuard(monitor);
  Object[] arguments =
    (timed ? new Object[] {guard, 0L, TimeUnit.MILLISECONDS} : new Object[] {guard});
  try {
   method.invoke(monitor, arguments);
   fail("expected IllegalMonitorStateException");
  } catch (InvocationTargetException e) {
   assertEquals(IllegalMonitorStateException.class, e.getTargetException().getClass());
  }
 }
};

代码示例来源:origin: com.google.guava/guava-tests

public void testLeaveWithoutEnterThrowsIMSE() {
 Monitor monitor = new Monitor();
 try {
  monitor.leave();
  fail("expected IllegalMonitorStateException");
 } catch (IllegalMonitorStateException expected) {
 }
}

代码示例来源:origin: org.opendaylight.iotdm/onem2m-protocol-mqtt

@Override
public void onSessionInitiated(ProviderContext session) {
  this.rpcReg = session.addRpcImplementation(Onem2mMqttClientService.class, this);
  this.dataBroker = session.getSALService(DataBroker.class);
  this.notifierService = session.getSALService(NotificationProviderService.class);
  crudMonitor = new Monitor();
  stats = Onem2mStats.getInstance();
  db = Onem2mDb.getInstance();
  db.initializeDatastore(dataBroker);
  onem2mService = session.getRpcService(Onem2mService.class);
  onem2mMqttClient = new Onem2mMqttAsyncClient();
  LOG.info("Onem2mMqttProvider Session Initiated ...");
}

代码示例来源:origin: com.google.guava/guava-tests

@Override protected final void setUp() throws Exception {
 boolean fair = new Random().nextBoolean();
 monitor = new Monitor(fair);
 tearDownStack.addTearDown(thread1 = new TestThread<>(monitor, "TestThread #1"));
 tearDownStack.addTearDown(thread2 = new TestThread<>(monitor, "TestThread #2"));
}

相关文章