阻塞返回条件: 1. 中断事件 2. 其他线程single()的weight > 当前阻塞等待的weight
3031323334353637383940
@Test public void test_simple() { final WeightBarrier barrier = new WeightBarrier(10); try { barrier.await(10);// 可以成功通过 } catch (InterruptedException e1) { want.fail(); } try {
4950515253545556575859
count.countDown(); return null; } }); barrier.await(11);// 会被阻塞 count.await(); executor.shutdown(); } catch (InterruptedException e) { want.fail(); }
6970717273747576777879
for (int i = 0; i < 10; i++) { final long index = i; executor.submit(new Callable() { public Object call() throws Exception { barrier.await(index); want.number(index).isLe(barrier.state()); count.countDown(); return null; } });