本文整理汇总了Java中java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject.signal方法的典型用法代码示例。如果您正苦于以下问题:Java ConditionObject.signal方法的具体用法?Java ConditionObject.signal怎么用?Java ConditionObject.signal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject
的用法示例。
在下文中一共展示了ConditionObject.signal方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSignal
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject; //导入方法依赖的package包/类
public void testSignal(final AwaitMethod awaitMethod) {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
final BooleanLatch acquired = new BooleanLatch();
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
sync.acquire();
assertTrue(acquired.releaseShared(0));
await(c, awaitMethod);
sync.release();
}});
acquired.acquireShared(0);
sync.acquire();
assertHasWaitersLocked(sync, c, t);
assertHasExclusiveQueuedThreads(sync, NO_THREADS);
c.signal();
assertHasWaitersLocked(sync, c, NO_THREADS);
assertHasExclusiveQueuedThreads(sync, t);
sync.release();
awaitTermination(t);
}
示例2: testSignal_IMSE
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject; //导入方法依赖的package包/类
/**
* Calling signal without holding sync throws IllegalMonitorStateException
*/
public void testSignal_IMSE() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
try {
c.signal();
shouldThrow();
} catch (IllegalMonitorStateException success) {}
assertHasWaitersUnlocked(sync, c, NO_THREADS);
}
示例3: testHasWaiters
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject; //导入方法依赖的package包/类
/**
* hasWaiters returns true when a thread is waiting, else false
*/
public void testHasWaiters() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
final BooleanLatch acquired = new BooleanLatch();
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
sync.acquire();
assertHasWaitersLocked(sync, c, NO_THREADS);
assertFalse(sync.hasWaiters(c));
assertTrue(acquired.releaseShared(0));
c.await();
sync.release();
}});
acquired.acquireShared(0);
sync.acquire();
assertHasWaitersLocked(sync, c, t);
assertHasExclusiveQueuedThreads(sync, NO_THREADS);
assertTrue(sync.hasWaiters(c));
c.signal();
assertHasWaitersLocked(sync, c, NO_THREADS);
assertHasExclusiveQueuedThreads(sync, t);
assertFalse(sync.hasWaiters(c));
sync.release();
awaitTermination(t);
assertHasWaitersUnlocked(sync, c, NO_THREADS);
}
示例4: testAwaitUninterruptibly
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject; //导入方法依赖的package包/类
/**
* awaitUninterruptibly is uninterruptible
*/
public void testAwaitUninterruptibly() {
final Mutex sync = new Mutex();
final ConditionObject condition = sync.newCondition();
final BooleanLatch pleaseInterrupt = new BooleanLatch();
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() {
sync.acquire();
assertTrue(pleaseInterrupt.releaseShared(0));
condition.awaitUninterruptibly();
assertTrue(Thread.interrupted());
assertHasWaitersLocked(sync, condition, NO_THREADS);
sync.release();
}});
pleaseInterrupt.acquireShared(0);
sync.acquire();
assertHasWaitersLocked(sync, condition, t);
sync.release();
t.interrupt();
assertHasWaitersUnlocked(sync, condition, t);
assertThreadBlocks(t, Thread.State.WAITING);
sync.acquire();
assertHasWaitersLocked(sync, condition, t);
assertHasExclusiveQueuedThreads(sync, NO_THREADS);
condition.signal();
assertHasWaitersLocked(sync, condition, NO_THREADS);
assertHasExclusiveQueuedThreads(sync, t);
sync.release();
awaitTermination(t);
}
示例5: testAwaitUninterruptibly
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject; //导入方法依赖的package包/类
/**
* awaitUninterruptibly is uninterruptible
*/
public void testAwaitUninterruptibly() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
final BooleanLatch pleaseInterrupt = new BooleanLatch();
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() {
sync.acquire();
assertTrue(pleaseInterrupt.releaseShared(0));
c.awaitUninterruptibly();
assertTrue(Thread.interrupted());
assertHasWaitersLocked(sync, c, NO_THREADS);
sync.release();
}});
pleaseInterrupt.acquireShared(0);
sync.acquire();
assertHasWaitersLocked(sync, c, t);
sync.release();
t.interrupt();
assertHasWaitersUnlocked(sync, c, t);
assertThreadStaysAlive(t);
sync.acquire();
assertHasWaitersLocked(sync, c, t);
assertHasExclusiveQueuedThreads(sync, NO_THREADS);
c.signal();
assertHasWaitersLocked(sync, c, NO_THREADS);
assertHasExclusiveQueuedThreads(sync, t);
sync.release();
awaitTermination(t);
}