本文整理汇总了Java中java.util.concurrent.locks.Lock.newCondition方法的典型用法代码示例。如果您正苦于以下问题:Java Lock.newCondition方法的具体用法?Java Lock.newCondition怎么用?Java Lock.newCondition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.locks.Lock
的用法示例。
在下文中一共展示了Lock.newCondition方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: AppContext
import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
/**
* Constructor for AppContext. This method is <i>not</i> public,
* nor should it ever be used as such. The proper way to construct
* an AppContext is through the use of SunToolkit.createNewAppContext.
* A ThreadGroup is created for the new AppContext, a Thread is
* created within that ThreadGroup, and that Thread calls
* SunToolkit.createNewAppContext before calling anything else.
* That creates both the new AppContext and its EventQueue.
*
* @param threadGroup The ThreadGroup for the new AppContext
* @see sun.awt.SunToolkit
* @since 1.2
*/
AppContext(ThreadGroup threadGroup) {
numAppContexts.incrementAndGet();
this.threadGroup = threadGroup;
threadGroup2appContext.put(threadGroup, this);
this.contextClassLoader =
AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
public ClassLoader run() {
return Thread.currentThread().getContextClassLoader();
}
});
// Initialize push/pop lock and its condition to be used by all the
// EventQueues within this AppContext
Lock eventQueuePushPopLock = new ReentrantLock();
put(EVENT_QUEUE_LOCK_KEY, eventQueuePushPopLock);
Condition eventQueuePushPopCond = eventQueuePushPopLock.newCondition();
put(EVENT_QUEUE_COND_KEY, eventQueuePushPopCond);
}
示例2: startThrift
import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
private void startThrift() throws Exception {
final Lock startLock = new ReentrantLock();
final Condition startCondition = startLock.newCondition();
final AtomicBoolean startedServing = new AtomicBoolean();
try (ServerSocket socket = new ServerSocket(0)) {
thriftPort = socket.getLocalPort();
}
conf.setVar(ConfVars.METASTOREURIS, getThriftConnectionUri());
final HiveConf hiveConf = new HiveConf(conf, HiveMetaStoreClient.class);
thriftServer.execute(new Runnable() {
@Override
public void run() {
try {
HadoopThriftAuthBridge bridge = new HadoopThriftAuthBridge23();
HiveMetaStore.startMetaStore(thriftPort, bridge, hiveConf, startLock, startCondition, startedServing);
} catch (Throwable e) {
LOG.error("Unable to start a Thrift server for Hive Metastore", e);
}
}
});
int i = 0;
while (i++ < 3) {
startLock.lock();
try {
if (startCondition.await(1, TimeUnit.MINUTES)) {
break;
}
} finally {
startLock.unlock();
}
if (i == 3) {
throw new RuntimeException("Maximum number of tries reached whilst waiting for Thrift server to be ready");
}
}
}
示例3: verifyNamespacedListIsBackedUpIntoProperFiles_WhenNamespacedListIsReloaded
import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
private void verifyNamespacedListIsBackedUpIntoProperFiles_WhenNamespacedListIsReloaded() throws Exception {
deleteBackups();
contextA.setNamespacedLists(Arrays.asList(new TestNamespacedList("integrationTest", "1", "2")));
Lock listUpdateLock = new ReentrantLock();
Condition updated = listUpdateLock.newCondition();
newBatchAppliedListener.setCallback(event -> {
log.info("Namespaced List updated in data store");
if (event.getData().getNamespacedLists().containsKey("integrationTest")) {
listUpdateLock.lock();
try {
updated.signalAll();
} finally {
listUpdateLock.unlock();
}
}
});
testHelperA.getDataStore().putNamespacedList();
listUpdateLock.lock();
try {
updated.await(1, TimeUnit.SECONDS);
} finally {
listUpdateLock.unlock();
}
log.info("Unlocked test. Keep going");
Thread.sleep(1000); // TODO: find better way to wait till all backup files are written
Assert.assertTrue("Namespaced list backup is absent", Files.exists(Paths.get(currentPath + File.separator + "namespacedlists.json")));
}
示例4: backupsAreUpdatedAfterDataSourceComesUp
import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
private void backupsAreUpdatedAfterDataSourceComesUp() throws Exception {
TestContext context = contextBuilder.withNamespacedList(NAMESPACED_LIST, "new value").build();
IntegrationTestHelper testHelper = prepareTestHelperForInitRedirectorModel(context);
Lock lock = new ReentrantLock();
Condition listUpdated = lock.newCondition();
newBatchAppliedListener.setCallback(event -> {
log.info("Namespaced Lists updated after zookeeper came up");
lock.lock();
try {
listUpdated.signalAll();
} finally {
lock.unlock();
}
});
dataStoreSupport.startZookeeper();
testHelper.getDataStore().setupEnvForContext();
lock.lock();
try {
listUpdated.await(3, TimeUnit.SECONDS);
} finally {
lock.unlock();
}
log.info("Unlocked test. Keep going");
NamespacedListsBatch namespacedListsFromBackup = testHelper.getBackups().getNamespacedLists();
Assert.assertTrue(namespacedListsFromBackup.getNamespacedLists().get(NAMESPACED_LIST).contains("new value"));
Assert.assertFalse(namespacedListsFromBackup.getNamespacedLists().get(NAMESPACED_LIST).contains(NAMESPACED_LIST_VALUE));
}
示例5: testAwaitUninterruptibly
import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
public void testAwaitUninterruptibly(boolean fair) {
final Lock lock = new ReentrantReadWriteLock(fair).writeLock();
final Condition condition = lock.newCondition();
final CountDownLatch pleaseInterrupt = new CountDownLatch(2);
Thread t1 = newStartedThread(new CheckedRunnable() {
public void realRun() {
// Interrupt before awaitUninterruptibly
lock.lock();
pleaseInterrupt.countDown();
Thread.currentThread().interrupt();
condition.awaitUninterruptibly();
assertTrue(Thread.interrupted());
lock.unlock();
}});
Thread t2 = newStartedThread(new CheckedRunnable() {
public void realRun() {
// Interrupt during awaitUninterruptibly
lock.lock();
pleaseInterrupt.countDown();
condition.awaitUninterruptibly();
assertTrue(Thread.interrupted());
lock.unlock();
}});
await(pleaseInterrupt);
t2.interrupt();
lock.lock();
lock.unlock();
assertThreadBlocks(t1, Thread.State.WAITING);
assertThreadBlocks(t2, Thread.State.WAITING);
lock.lock();
condition.signalAll();
lock.unlock();
awaitTermination(t1);
awaitTermination(t2);
}
示例6: PoolEntryFuture
import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
PoolEntryFuture(final Lock lock, final FutureCallback<T> callback) {
super();
this.lock = lock;
this.condition = lock.newCondition();
this.callback = callback;
}
示例7: backupsAreUpdatedAfterNamespacedListIsChangedInDataStore
import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
private void backupsAreUpdatedAfterNamespacedListIsChangedInDataStore() throws Exception {
TestContext context = contextBuilder.withNamespacedList("NewList", "value1", "value2").build();
IntegrationTestHelper testHelper = prepareTestHelperForUpdateRedirectorModel(context);
Lock lock = new ReentrantLock();
Condition listUpdated = lock.newCondition();
newBatchAppliedListener.setCallback(unchecked(event -> {
log.info("New namespaced list is applied: {}", event.getData().getNamespacedLists());
if (event.getData() != null && event.getData().getNamespacedLists() != null) {
if (event.getData().getNamespacedLists().containsKey("NewList")) {
log.info("Event for update of new namespaced list happened. Continue processing");
} else {
log.info("Skip this event");
return;
}
}
lock.lock();
try {
listUpdated.signalAll();
} finally {
lock.unlock();
}
}));
lock.lock();
try {
testHelper.getDataStore().putNamespacedList();
if (listUpdated.await(1, TimeUnit.SECONDS)) {
log.info("Namespaced list is applied. Going to verification");
} else {
log.info("Timeout exceed. Unlocking test");
}
} finally {
lock.unlock();
}
NamespacedListsBatch namespacedListsFromBackup = testHelper.getBackups().getNamespacedLists();
log.info("Got namespaced list from backup {}", namespacedListsFromBackup.getNamespacedLists());
Assert.assertTrue(namespacedListsFromBackup.getNamespacedLists().get("NewList").contains("value1"));
Assert.assertTrue(namespacedListsFromBackup.getNamespacedLists().get("NewList").contains("value2"));
}