本文整理匯總了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();
}
}
示例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);
}
}
示例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());
}
示例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);
}
}
示例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();
}
}
示例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));
}
}
示例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();
}
示例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);
}
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
}
示例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);
}
}
示例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();
}