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


Java ConditionObject.signal方法代码示例

本文整理汇总了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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:AbstractQueuedLongSynchronizerTest.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:AbstractQueuedLongSynchronizerTest.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:AbstractQueuedLongSynchronizerTest.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:AbstractQueuedLongSynchronizerTest.java

示例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);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:34,代码来源:AbstractQueuedLongSynchronizerTest.java


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