当前位置: 首页>>代码示例>>Java>>正文


Java BrokenBarrierException类代码示例

本文整理汇总了Java中java.util.concurrent.BrokenBarrierException的典型用法代码示例。如果您正苦于以下问题:Java BrokenBarrierException类的具体用法?Java BrokenBarrierException怎么用?Java BrokenBarrierException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BrokenBarrierException类属于java.util.concurrent包,在下文中一共展示了BrokenBarrierException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCustomScheduler_deadlock

import java.util.concurrent.BrokenBarrierException; //导入依赖的package包/类
public void testCustomScheduler_deadlock() throws InterruptedException, BrokenBarrierException {
  final CyclicBarrier inGetNextSchedule = new CyclicBarrier(2);
  // This will flakily deadlock, so run it multiple times to increase the flake likelihood
  for (int i = 0; i < 1000; i++) {
    Service service = new AbstractScheduledService() {
      @Override protected void runOneIteration() {}
      @Override protected Scheduler scheduler() {
        return new CustomScheduler() {
          @Override protected Schedule getNextSchedule() throws Exception {
            if (state() != State.STARTING) {
              inGetNextSchedule.await();
              Thread.yield();
              throw new RuntimeException("boom");
            }
            return new Schedule(0, TimeUnit.NANOSECONDS);
          }
        };
      }
    };
    service.startAsync().awaitRunning();
    inGetNextSchedule.await();
    service.stopAsync();
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:25,代码来源:AbstractScheduledServiceTest.java

示例2: await

import java.util.concurrent.BrokenBarrierException; //导入依赖的package包/类
public void await() {
    if(0 == delay) {
        log.info("No pause between retry");
        return;
    }
    final Timer wakeup = new Timer();
    final CyclicBarrier wait = new CyclicBarrier(2);
    // Schedule for immediate execution with an interval of 1s
    wakeup.scheduleAtFixedRate(new PauserTimerTask(wait), 0, 1000);
    try {
        // Wait for notify from wakeup timer
        wait.await();
    }
    catch(InterruptedException | BrokenBarrierException e) {
        log.error(e.getMessage(), e);
    }
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:18,代码来源:BackgroundActionPauser.java

示例3: testConcurrent

import java.util.concurrent.BrokenBarrierException; //导入依赖的package包/类
@Test
public void testConcurrent() throws Exception {
    final TransferQueue queue = new TransferQueue(1);
    final DownloadTransfer transfer = new DownloadTransfer(new Host(new TestProtocol()), new Path("/t", EnumSet.of(Path.Type.directory)), null);
    queue.add(transfer, new DisabledProgressListener());
    final AtomicBoolean added = new AtomicBoolean();
    final CyclicBarrier wait = new CyclicBarrier(2);
    new Thread(new Runnable() {
        @Override
        public void run() {
            queue.add(new DownloadTransfer(new Host(new TestProtocol()), new Path("/t", EnumSet.of(Path.Type.directory)), null), new DisabledProgressListener());
            added.set(true);
            try {
                wait.await();
            }
            catch(InterruptedException | BrokenBarrierException e) {
                fail();
            }
        }
    }).start();
    assertFalse(added.get());
    queue.remove(transfer);
    wait.await();
    assertTrue(added.get());
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:26,代码来源:TransferQueueTest.java

示例4: testTxConflictHandling

import java.util.concurrent.BrokenBarrierException; //导入依赖的package包/类
@Test
public void testTxConflictHandling() throws InterruptedException, BrokenBarrierException, TimeoutException, IOException {
	// Test creation of user in current thread
	int nFriendsBefore;
	try (Tx tx = graph.tx()) {
		p = addPersonWithFriends(tx.getGraph(), "Person2");
		manipulatePerson(tx.getGraph(), p);
		tx.success();
		nFriendsBefore = p.getFriends().size();
	}

	CyclicBarrier b = new CyclicBarrier(3);
	addFriendToPersonInThread(p, b);
	addFriendToPersonInThread(p, b);

	// Wait until both threads have started their transactions
	b.await();
	Thread.sleep(2000);
	try (Tx tx = graph.tx()) {
		// Reload the person in a fresh transaction
		p = tx.getGraph().getFramedVertexExplicit(Person.class, p.getId());
		int nFriendsAfter = p.getFriends().size();
		assertEquals(nFriendsBefore + 2, nFriendsAfter);
	}

}
 
开发者ID:Syncleus,项目名称:Ferma-OrientDB,代码行数:27,代码来源:TxTest.java

示例5: run

import java.util.concurrent.BrokenBarrierException; //导入依赖的package包/类
@Override
public void run() {
    int counter;
    System.out.printf("%s: Processing lines from %d to %d.\n", Thread.currentThread().getName(), firstRow, lastRow);
    for (int i = firstRow; i < lastRow; i++) {
        int row[] = mock.getRow(i);
        counter = 0;
        for (int aRow : row) {
            if (aRow == number) {
                counter++;
            }
        }
        results.setData(i, counter);
    }
    System.out.printf("%s: Lines processed.\n", Thread.currentThread().getName());
    try {
        barrier.await();
    } catch (InterruptedException | BrokenBarrierException e) {
        e.printStackTrace();
    }
}
 
开发者ID:firery,项目名称:java-concurrency-cheatsheet,代码行数:22,代码来源:Main.java

示例6: main

import java.util.concurrent.BrokenBarrierException; //导入依赖的package包/类
/**
 * 版本3.0.9以下存在多线程初始化问题,这个类作为一个样例
 */
public static void main(String[] args) throws InterruptedException, BrokenBarrierException {
    System.out.println(Arrays.asList(splitWord));
    for (int j = 0; j < 1000; j++) {
        CyclicBarrier barrier = new CyclicBarrier(11, null);
        for (int i = 0; i < 10; i++) {
            Thread t = new Thread(new Worker(barrier), "t" + i);
            t.start();
        }
        Thread.sleep(500);
        barrier.await();
        while (barrier.getNumberWaiting() > 0) {
            Thread.sleep(1000);
        }
        Thread.sleep(1000);
        System.out.println(Arrays.asList(splitWord));
    }
}
 
开发者ID:alibaba,项目名称:QLExpress,代码行数:21,代码来源:CrashTest.java

示例7: testBlockNewContainerRequestsOnStartAndResync

import java.util.concurrent.BrokenBarrierException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test(timeout=60000)
public void testBlockNewContainerRequestsOnStartAndResync()
    throws IOException, InterruptedException, YarnException {
  NodeManager nm = new TestNodeManager2();
  YarnConfiguration conf = createNMConfig();
  conf.setBoolean(YarnConfiguration.RM_WORK_PRESERVING_RECOVERY_ENABLED, false);
  nm.init(conf);
  nm.start();

  // Start the container in running state
  ContainerId cId = TestNodeManagerShutdown.createContainerId();
  TestNodeManagerShutdown.startContainer(nm, cId, localFS, tmpDir,
    processStartFile);

  nm.getNMDispatcher().getEventHandler()
    .handle(new NodeManagerEvent(NodeManagerEventType.RESYNC));
  try {
    syncBarrier.await();
  } catch (BrokenBarrierException e) {
  }
  Assert.assertFalse(assertionFailedInThread.get());
  nm.stop();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:25,代码来源:TestNodeManagerResync.java

示例8: handle

import java.util.concurrent.BrokenBarrierException; //导入依赖的package包/类
@Override
public void handle(HttpExchange exchange) throws IOException {
    count++;
    try {
        switch(count) {
            case 0:
                AuthenticationHandler.errorReply(exchange,
                        "Basic realm=\"realm1\"");
                break;
            case 1:
                t1Cond1.await();
                t1cond2latch.await();
                AuthenticationHandler.okReply(exchange);
                break;
            default:
                System.out.println ("Unexpected request");
        }
    } catch (InterruptedException |
                     BrokenBarrierException e)
            {
                throw new RuntimeException(e);
            }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:B4769350.java

示例9: main

import java.util.concurrent.BrokenBarrierException; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    int maxThreads = 5;
    if (args.length > 0)
        maxThreads = Integer.parseInt(args[0]);

    print = true;

    for (int i = 2; i <= maxThreads; i += (i+1) >>> 1) {
        System.out.print("Threads: " + i);
        try {
            new FutureLoop(i, rnd.split()).test();
        }
        catch (BrokenBarrierException bb) {
            // OK; ignore
        }
        catch (ExecutionException ee) {
            // OK; ignore
        }
        Thread.sleep(TIMEOUT);
    }
    pool.shutdown();
    if (! pool.awaitTermination(6 * LONG_DELAY_MS, MILLISECONDS))
        throw new Error();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:CancelledFutureLoops.java

示例10: testAwait1_Interrupted_BrokenBarrier

import java.util.concurrent.BrokenBarrierException; //导入依赖的package包/类
/**
 * An interruption in one party causes others waiting in await to
 * throw BrokenBarrierException
 */
public void testAwait1_Interrupted_BrokenBarrier() {
    final CyclicBarrier c = new CyclicBarrier(3);
    final CountDownLatch pleaseInterrupt = new CountDownLatch(2);
    Thread t1 = new ThreadShouldThrow(InterruptedException.class) {
        public void realRun() throws Exception {
            pleaseInterrupt.countDown();
            c.await();
        }};
    Thread t2 = new ThreadShouldThrow(BrokenBarrierException.class) {
        public void realRun() throws Exception {
            pleaseInterrupt.countDown();
            c.await();
        }};

    t1.start();
    t2.start();
    await(pleaseInterrupt);
    t1.interrupt();
    awaitTermination(t1);
    awaitTermination(t2);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:CyclicBarrierTest.java

示例11: testAwait2_Interrupted_BrokenBarrier

import java.util.concurrent.BrokenBarrierException; //导入依赖的package包/类
/**
 * An interruption in one party causes others waiting in timed await to
 * throw BrokenBarrierException
 */
public void testAwait2_Interrupted_BrokenBarrier() throws Exception {
    final CyclicBarrier c = new CyclicBarrier(3);
    final CountDownLatch pleaseInterrupt = new CountDownLatch(2);
    Thread t1 = new ThreadShouldThrow(InterruptedException.class) {
        public void realRun() throws Exception {
            pleaseInterrupt.countDown();
            c.await(LONG_DELAY_MS, MILLISECONDS);
        }};
    Thread t2 = new ThreadShouldThrow(BrokenBarrierException.class) {
        public void realRun() throws Exception {
            pleaseInterrupt.countDown();
            c.await(LONG_DELAY_MS, MILLISECONDS);
        }};

    t1.start();
    t2.start();
    await(pleaseInterrupt);
    t1.interrupt();
    awaitTermination(t1);
    awaitTermination(t2);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:CyclicBarrierTest.java

示例12: testReset_BrokenBarrier

import java.util.concurrent.BrokenBarrierException; //导入依赖的package包/类
/**
 * A reset of an active barrier causes waiting threads to throw
 * BrokenBarrierException
 */
public void testReset_BrokenBarrier() throws InterruptedException {
    final CyclicBarrier c = new CyclicBarrier(3);
    final CountDownLatch pleaseReset = new CountDownLatch(2);
    Thread t1 = new ThreadShouldThrow(BrokenBarrierException.class) {
        public void realRun() throws Exception {
            pleaseReset.countDown();
            c.await();
        }};
    Thread t2 = new ThreadShouldThrow(BrokenBarrierException.class) {
        public void realRun() throws Exception {
            pleaseReset.countDown();
            c.await();
        }};

    t1.start();
    t2.start();
    await(pleaseReset);

    awaitNumberWaiting(c, 2);
    c.reset();
    awaitTermination(t1);
    awaitTermination(t2);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:CyclicBarrierTest.java

示例13: testResetAfterCommandException

import java.util.concurrent.BrokenBarrierException; //导入依赖的package包/类
/**
 * Reset of a barrier after a failed command reinitializes it.
 */
public void testResetAfterCommandException() throws Exception {
    final CyclicBarrier barrier =
        new CyclicBarrier(3, new Runnable() {
                public void run() {
                    throw new NullPointerException(); }});
    for (int i = 0; i < 2; i++) {
        final CyclicBarrier start = new CyclicBarrier(3);
        Thread t1 = new ThreadShouldThrow(BrokenBarrierException.class) {
            public void realRun() throws Exception {
                start.await();
                barrier.await();
            }};

        Thread t2 = new ThreadShouldThrow(BrokenBarrierException.class) {
            public void realRun() throws Exception {
                start.await();
                barrier.await();
            }};

        t1.start();
        t2.start();
        start.await();
        awaitNumberWaiting(barrier, 2);
        try {
            barrier.await();
            shouldThrow();
        } catch (NullPointerException success) {}
        awaitTermination(t1);
        awaitTermination(t2);
        assertTrue(barrier.isBroken());
        assertEquals(0, barrier.getNumberWaiting());
        barrier.reset();
        assertFalse(barrier.isBroken());
        assertEquals(0, barrier.getNumberWaiting());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:CyclicBarrierTest.java

示例14: handle

import java.util.concurrent.BrokenBarrierException; //导入依赖的package包/类
@Override
public void handle(HttpExchange exchange) throws IOException {
    count++;
    try {
        switch(count) {
            case 0:
                AuthenticationHandler.errorReply(exchange,
                        "Basic realm=\"realm1\"");
                break;
            case 1:
                t1Cond1.await();
                AuthenticationHandler.okReply(exchange);
                break;
            default:
                System.out.println ("Unexpected request");
        }
    } catch (InterruptedException |
                     BrokenBarrierException e)
            {
                throw new RuntimeException(e);
            }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:B4769350.java

示例15: testBlockNewContainerRequestsOnStartAndResync

import java.util.concurrent.BrokenBarrierException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test(timeout=60000)
public void testBlockNewContainerRequestsOnStartAndResync()
    throws IOException, InterruptedException, YarnException {
  NodeManager nm = new TestNodeManager2();
  int port = ServerSocketUtil.getPort(49154, 10);
  YarnConfiguration conf = createNMConfig(port);
  conf.setBoolean(YarnConfiguration.RM_WORK_PRESERVING_RECOVERY_ENABLED, false);
  nm.init(conf);
  nm.start();

  // Start the container in running state
  ContainerId cId = TestNodeManagerShutdown.createContainerId();
  TestNodeManagerShutdown.startContainer(nm, cId, localFS, tmpDir,
      processStartFile, port);

  nm.getNMDispatcher().getEventHandler()
    .handle(new NodeManagerEvent(NodeManagerEventType.RESYNC));
  try {
    syncBarrier.await();
  } catch (BrokenBarrierException e) {
  }
  Assert.assertFalse(assertionFailedInThread.get());
  nm.stop();
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:26,代码来源:TestNodeManagerResync.java


注:本文中的java.util.concurrent.BrokenBarrierException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。