本文整理汇总了Java中java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject类的典型用法代码示例。如果您正苦于以下问题:Java ConditionObject类的具体用法?Java ConditionObject怎么用?Java ConditionObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConditionObject类属于java.util.concurrent.locks.AbstractQueuedLongSynchronizer包,在下文中一共展示了ConditionObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: await
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject; //导入依赖的package包/类
/**
* Awaits condition using the specified AwaitMethod.
*/
void await(ConditionObject c, AwaitMethod awaitMethod)
throws InterruptedException {
long timeoutMillis = 2 * LONG_DELAY_MS;
switch (awaitMethod) {
case await:
c.await();
break;
case awaitTimed:
assertTrue(c.await(timeoutMillis, MILLISECONDS));
break;
case awaitNanos:
long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis);
long nanosRemaining = c.awaitNanos(nanosTimeout);
assertTrue(nanosRemaining > 0);
break;
case awaitUntil:
assertTrue(c.awaitUntil(delayedDate(timeoutMillis)));
break;
default:
throw new AssertionError();
}
}
示例2: 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);
}
示例3: assertHasWaitersUnlocked
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject; //导入依赖的package包/类
/**
* Checks that condition c has exactly the given waiter threads,
* after acquiring mutex.
*/
void assertHasWaitersUnlocked(Mutex sync, ConditionObject c,
Thread... threads) {
sync.acquire();
assertHasWaitersLocked(sync, c, threads);
sync.release();
}
示例4: assertHasWaitersLocked
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject; //导入依赖的package包/类
/**
* Checks that condition c has exactly the given waiter threads.
*/
void assertHasWaitersLocked(Mutex sync, ConditionObject c,
Thread... threads) {
assertEquals(threads.length > 0, sync.hasWaiters(c));
assertEquals(threads.length, sync.getWaitQueueLength(c));
assertEquals(threads.length == 0, sync.getWaitingThreads(c).isEmpty());
assertEquals(threads.length, sync.getWaitingThreads(c).size());
assertEquals(new HashSet<Thread>(sync.getWaitingThreads(c)),
new HashSet<Thread>(Arrays.asList(threads)));
}
示例5: assertAwaitTimesOut
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject; //导入依赖的package包/类
/**
* Checks that awaiting the given condition times out (using the
* default timeout duration).
*/
void assertAwaitTimesOut(ConditionObject c, AwaitMethod awaitMethod) {
final long timeoutMillis = timeoutMillis();
final long startTime;
try {
switch (awaitMethod) {
case awaitTimed:
startTime = System.nanoTime();
assertFalse(c.await(timeoutMillis, MILLISECONDS));
assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
break;
case awaitNanos:
startTime = System.nanoTime();
long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis);
long nanosRemaining = c.awaitNanos(nanosTimeout);
assertTrue(nanosRemaining <= 0);
assertTrue(nanosRemaining > -MILLISECONDS.toNanos(LONG_DELAY_MS));
assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
break;
case awaitUntil:
// We shouldn't assume that nanoTime and currentTimeMillis
// use the same time source, so don't use nanoTime here.
java.util.Date delayedDate = delayedDate(timeoutMillis);
assertFalse(c.awaitUntil(delayedDate(timeoutMillis)));
assertTrue(new java.util.Date().getTime() >= delayedDate.getTime());
break;
default:
throw new UnsupportedOperationException();
}
} catch (InterruptedException ie) { threadUnexpectedException(ie); }
}
示例6: testOwns
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject; //导入依赖的package包/类
/**
* owns is true for a condition created by sync else false
*/
public void testOwns() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
final Mutex sync2 = new Mutex();
assertTrue(sync.owns(c));
assertFalse(sync2.owns(c));
}
示例7: testAwait_IMSE
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject; //导入依赖的package包/类
/**
* Calling await without holding sync throws IllegalMonitorStateException
*/
public void testAwait_IMSE() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
for (AwaitMethod awaitMethod : AwaitMethod.values()) {
long startTime = System.nanoTime();
try {
await(c, awaitMethod);
shouldThrow();
} catch (IllegalMonitorStateException success) {
} catch (InterruptedException e) { threadUnexpectedException(e); }
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
}
}
示例8: 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);
}
示例9: testSignalAll_IMSE
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject; //导入依赖的package包/类
/**
* Calling signalAll without holding sync throws IllegalMonitorStateException
*/
public void testSignalAll_IMSE() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
try {
c.signalAll();
shouldThrow();
} catch (IllegalMonitorStateException success) {}
}
示例10: testAwait_Timeout
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject; //导入依赖的package包/类
public void testAwait_Timeout(AwaitMethod awaitMethod) {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
sync.acquire();
assertAwaitTimesOut(c, awaitMethod);
sync.release();
}
示例11: testHasWaitersIAE
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject; //导入依赖的package包/类
/**
* hasWaiters throws IllegalArgumentException if not owned
*/
public void testHasWaitersIAE() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
final Mutex sync2 = new Mutex();
try {
sync2.hasWaiters(c);
shouldThrow();
} catch (IllegalArgumentException success) {}
assertHasWaitersUnlocked(sync, c, NO_THREADS);
}
示例12: testHasWaitersIMSE
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject; //导入依赖的package包/类
/**
* hasWaiters throws IllegalMonitorStateException if not synced
*/
public void testHasWaitersIMSE() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
try {
sync.hasWaiters(c);
shouldThrow();
} catch (IllegalMonitorStateException success) {}
assertHasWaitersUnlocked(sync, c, NO_THREADS);
}
示例13: testGetWaitQueueLengthIAE
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject; //导入依赖的package包/类
/**
* getWaitQueueLength throws IllegalArgumentException if not owned
*/
public void testGetWaitQueueLengthIAE() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
final Mutex sync2 = new Mutex();
try {
sync2.getWaitQueueLength(c);
shouldThrow();
} catch (IllegalArgumentException success) {}
assertHasWaitersUnlocked(sync, c, NO_THREADS);
}
示例14: testGetWaitQueueLengthIMSE
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject; //导入依赖的package包/类
/**
* getWaitQueueLength throws IllegalMonitorStateException if not synced
*/
public void testGetWaitQueueLengthIMSE() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
try {
sync.getWaitQueueLength(c);
shouldThrow();
} catch (IllegalMonitorStateException success) {}
assertHasWaitersUnlocked(sync, c, NO_THREADS);
}
示例15: testGetWaitingThreadsIAE
import java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject; //导入依赖的package包/类
/**
* getWaitingThreads throws IllegalArgumentException if not owned
*/
public void testGetWaitingThreadsIAE() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
final Mutex sync2 = new Mutex();
try {
sync2.getWaitingThreads(c);
shouldThrow();
} catch (IllegalArgumentException success) {}
assertHasWaitersUnlocked(sync, c, NO_THREADS);
}