本文整理汇总了Java中java.util.concurrent.locks.Condition.signal方法的典型用法代码示例。如果您正苦于以下问题:Java Condition.signal方法的具体用法?Java Condition.signal怎么用?Java Condition.signal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.locks.Condition
的用法示例。
在下文中一共展示了Condition.signal方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deallocate
import java.util.concurrent.locks.Condition; //导入方法依赖的package包/类
/**
* Return buffers to the pool. If they are of the poolable size add them to the free list, otherwise just mark the
* memory as free.
*
* @param buffer The buffer to return
* @param size The size of the buffer to mark as deallocated, note that this may be smaller than buffer.capacity
* since the buffer may re-allocate itself during in-place compression
*/
// 释放ByteBuffer,返回到pool里
public void deallocate(ByteBuffer buffer, int size) {
lock.lock();
try {
// 如果byteBuffer的大小是poolablesize,放入free队列中进行管理
if (size == this.poolableSize && size == buffer.capacity()) {
buffer.clear();
this.free.add(buffer);
} else {
// 释放的ByteBuffer的大小不是poolableSize,不会服用ByteBuffer,仅修改availableMemory
this.availableMemory += size;
}
// 唤醒一个因空间不足而阻塞的线程
Condition moreMem = this.waiters.peekFirst();
if (moreMem != null)
moreMem.signal();
} finally {
// 解锁
lock.unlock();
}
}
示例2: testAwait
import java.util.concurrent.locks.Condition; //导入方法依赖的package包/类
public void testAwait(boolean fair) {
final PublicReentrantReadWriteLock lock =
new PublicReentrantReadWriteLock(fair);
final Condition c = lock.writeLock().newCondition();
final CountDownLatch locked = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
lock.writeLock().lock();
locked.countDown();
c.await();
lock.writeLock().unlock();
}});
await(locked);
lock.writeLock().lock();
assertHasWaiters(lock, c, t);
c.signal();
assertHasNoWaiters(lock, c);
assertTrue(t.isAlive());
lock.writeLock().unlock();
awaitTermination(t);
}
示例3: testGetWaitQueueLength
import java.util.concurrent.locks.Condition; //导入方法依赖的package包/类
public void testGetWaitQueueLength(boolean fair) {
final PublicReentrantReadWriteLock lock =
new PublicReentrantReadWriteLock(fair);
final Condition c = lock.writeLock().newCondition();
final CountDownLatch locked = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
lock.writeLock().lock();
assertEquals(0, lock.getWaitQueueLength(c));
locked.countDown();
c.await();
lock.writeLock().unlock();
}});
await(locked);
lock.writeLock().lock();
assertHasWaiters(lock, c, t);
assertEquals(1, lock.getWaitQueueLength(c));
c.signal();
assertHasNoWaiters(lock, c);
assertEquals(0, lock.getWaitQueueLength(c));
lock.writeLock().unlock();
awaitTermination(t);
}
示例4: testAwait
import java.util.concurrent.locks.Condition; //导入方法依赖的package包/类
public void testAwait(boolean fair) {
final PublicReentrantLock lock = new PublicReentrantLock(fair);
final Condition c = lock.newCondition();
final CountDownLatch locked = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
lock.lock();
locked.countDown();
c.await();
lock.unlock();
}});
await(locked);
lock.lock();
assertHasWaiters(lock, c, t);
c.signal();
assertHasNoWaiters(lock, c);
assertTrue(t.isAlive());
lock.unlock();
awaitTermination(t);
}
示例5: signal
import java.util.concurrent.locks.Condition; //导入方法依赖的package包/类
private static void signal(Lock lock, Condition condition, Runnable runnable) {
boolean interrupted = Thread.interrupted();
lock.lock();
try {
runnable.run();
condition.signal();
} finally {
lock.unlock();
if (interrupted) {
Thread.currentThread().interrupt();
}
}
}
示例6: testSignal_IMSE
import java.util.concurrent.locks.Condition; //导入方法依赖的package包/类
public void testSignal_IMSE(boolean fair) {
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
final Condition c = lock.writeLock().newCondition();
try {
c.signal();
shouldThrow();
} catch (IllegalMonitorStateException success) {}
}
示例7: testHasWaiters
import java.util.concurrent.locks.Condition; //导入方法依赖的package包/类
public void testHasWaiters(boolean fair) {
final PublicReentrantReadWriteLock lock =
new PublicReentrantReadWriteLock(fair);
final Condition c = lock.writeLock().newCondition();
final CountDownLatch locked = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
lock.writeLock().lock();
assertHasNoWaiters(lock, c);
assertFalse(lock.hasWaiters(c));
locked.countDown();
c.await();
assertHasNoWaiters(lock, c);
assertFalse(lock.hasWaiters(c));
lock.writeLock().unlock();
}});
await(locked);
lock.writeLock().lock();
assertHasWaiters(lock, c, t);
assertTrue(lock.hasWaiters(c));
c.signal();
assertHasNoWaiters(lock, c);
assertFalse(lock.hasWaiters(c));
lock.writeLock().unlock();
awaitTermination(t);
assertHasNoWaiters(lock, c);
}
示例8: testSignal_IMSE
import java.util.concurrent.locks.Condition; //导入方法依赖的package包/类
public void testSignal_IMSE(boolean fair) {
final ReentrantLock lock = new ReentrantLock(fair);
final Condition c = lock.newCondition();
try {
c.signal();
shouldThrow();
} catch (IllegalMonitorStateException success) {}
}
示例9: testHasWaiters
import java.util.concurrent.locks.Condition; //导入方法依赖的package包/类
public void testHasWaiters(boolean fair) {
final PublicReentrantLock lock = new PublicReentrantLock(fair);
final Condition c = lock.newCondition();
final CountDownLatch pleaseSignal = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
lock.lock();
assertHasNoWaiters(lock, c);
assertFalse(lock.hasWaiters(c));
pleaseSignal.countDown();
c.await();
assertHasNoWaiters(lock, c);
assertFalse(lock.hasWaiters(c));
lock.unlock();
}});
await(pleaseSignal);
lock.lock();
assertHasWaiters(lock, c, t);
assertTrue(lock.hasWaiters(c));
c.signal();
assertHasNoWaiters(lock, c);
assertFalse(lock.hasWaiters(c));
lock.unlock();
awaitTermination(t);
assertHasNoWaiters(lock, c);
}
示例10: subQueryFinished
import java.util.concurrent.locks.Condition; //导入方法依赖的package包/类
private void subQueryFinished(AtomicInteger subNodes, ReentrantLock lock, AtomicBoolean finished, Condition finishSubQuery) {
if (subNodes.decrementAndGet() == 0) {
lock.lock();
try {
finished.set(true);
finishSubQuery.signal();
} finally {
lock.unlock();
}
}
}
示例11: testSignalWakesFifo
import java.util.concurrent.locks.Condition; //导入方法依赖的package包/类
public void testSignalWakesFifo(boolean fair) {
final PublicReentrantLock lock =
new PublicReentrantLock(fair);
final Condition c = lock.newCondition();
final CountDownLatch locked1 = new CountDownLatch(1);
final CountDownLatch locked2 = new CountDownLatch(1);
Thread t1 = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
lock.lock();
locked1.countDown();
c.await();
lock.unlock();
}});
await(locked1);
Thread t2 = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
lock.lock();
locked2.countDown();
c.await();
lock.unlock();
}});
await(locked2);
lock.lock();
assertHasWaiters(lock, c, t1, t2);
assertFalse(lock.hasQueuedThreads());
c.signal();
assertHasWaiters(lock, c, t2);
assertTrue(lock.hasQueuedThread(t1));
assertFalse(lock.hasQueuedThread(t2));
c.signal();
assertHasNoWaiters(lock, c);
assertTrue(lock.hasQueuedThread(t1));
assertTrue(lock.hasQueuedThread(t2));
lock.unlock();
awaitTermination(t1);
awaitTermination(t2);
}