本文整理了Java中java.lang.Object.wait()
方法的一些代码示例,展示了Object.wait()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Object.wait()
方法的具体详情如下:
包路径:java.lang.Object
类名称:Object
方法名:wait
暂无
代码示例来源:origin: square/okhttp
/** For testing: waits until {@code requiredPongCount} pings have been received from the peer. */
synchronized void awaitPong() throws InterruptedException {
while (awaitingPong) {
wait();
}
}
代码示例来源:origin: stackoverflow.com
Object mon = ...;
synchronized (mon) {
mon.wait();
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Blocks until the event becomes the signaled state.
*
* <p>
* This method blocks infinitely until a value is offered.
*/
public void block() throws InterruptedException {
synchronized (lock) {
while(!signaled)
lock.wait();
}
}
代码示例来源:origin: apache/kafka
synchronized R await() throws InterruptedException, ExecutionException {
while (true) {
if (exception != null)
wrapAndThrow(exception);
if (done)
return value;
this.wait();
}
}
代码示例来源:origin: square/okhttp
/**
* Like {@link #wait}, but throws an {@code InterruptedIOException} when interrupted instead of
* the more awkward {@link InterruptedException}.
*/
void waitForIo() throws InterruptedIOException {
try {
wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt(); // Retain interrupted status.
throw new InterruptedIOException();
}
}
代码示例来源:origin: iluwatar/java-design-patterns
@Override
public void lock() {
synchronized (globalMutex) {
// Wait until the lock is free.
while (!isLockFree()) {
try {
globalMutex.wait();
} catch (InterruptedException e) {
LOGGER.info("InterruptedException while waiting for globalMutex to begin writing", e);
Thread.currentThread().interrupt();
}
}
// When the lock is free, acquire it by placing an entry in globalMutex
globalMutex.add(this);
}
}
代码示例来源:origin: iluwatar/java-design-patterns
/**
* Acquire the globalMutex lock on behalf of current and future concurrent readers. Make sure no writers currently
* owns the lock.
*/
private void acquireForReaders() {
// Try to get the globalMutex lock for the first reader
synchronized (globalMutex) {
// If the no one get the lock or the lock is locked by reader, just set the reference
// to the globalMutex to indicate that the lock is locked by Reader.
while (doesWriterOwnThisLock()) {
try {
globalMutex.wait();
} catch (InterruptedException e) {
LOGGER.info("InterruptedException while waiting for globalMutex in acquireForReaders", e);
Thread.currentThread().interrupt();
}
}
globalMutex.add(this);
}
}
代码示例来源:origin: spring-projects/spring-framework
public void doWait() {
this.counter++;
// wait until stop is called
synchronized (this.lock) {
try {
this.lock.wait();
}
catch (InterruptedException e) {
// fall through
}
}
}
代码示例来源:origin: skylot/jadx
private static boolean test() {
try {
synchronized (obj) {
obj.wait(5);
}
return true;
} catch (InterruptedException e) {
return false;
}
}
}
代码示例来源:origin: libgdx/libgdx
void destroy () {
synchronized (synch) {
running = false;
destroy = true;
while (destroy) {
try {
synch.wait();
} catch (InterruptedException ex) {
Gdx.app.log(LOG_TAG, "waiting for destroy synchronization failed!");
}
}
}
}
代码示例来源:origin: jenkinsci/jenkins
public void waitUntilOffline() throws InterruptedException {
synchronized (statusChangeLock) {
while (!isOffline())
statusChangeLock.wait(1000);
}
}
代码示例来源:origin: libgdx/libgdx
void destroy () {
synchronized (synch) {
running = false;
destroy = true;
while (destroy) {
try {
synch.wait();
} catch (InterruptedException ex) {
Gdx.app.log(LOG_TAG, "waiting for destroy synchronization failed!");
}
}
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Blocks until the node becomes online/offline.
*/
public void waitUntilOnline() throws InterruptedException {
synchronized (statusChangeLock) {
while (!isOnline())
statusChangeLock.wait(1000);
}
}
代码示例来源:origin: spring-projects/spring-framework
private void executeAndWait(SimpleAsyncTaskExecutor executor, Runnable task, Object monitor) {
synchronized (monitor) {
executor.execute(task);
try {
monitor.wait();
}
catch (InterruptedException ignored) {
}
}
}
代码示例来源:origin: spring-projects/spring-framework
public synchronized void waitForCompletion() {
try {
wait(WAIT_TIME);
}
catch (InterruptedException ex) {
fail("Didn't finish the async job in " + WAIT_TIME + " milliseconds");
}
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public void doSubscribe(URL url, NotifyListener listener) {
if (Constants.ANY_VALUE.equals(url.getServiceInterface())) {
admin = true;
}
multicast(Constants.SUBSCRIBE + " " + url.toFullString());
synchronized (listener) {
try {
listener.wait(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
} catch (InterruptedException e) {
}
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public void doSubscribe(URL url, NotifyListener listener) {
if (Constants.ANY_VALUE.equals(url.getServiceInterface())) {
admin = true;
}
multicast(Constants.SUBSCRIBE + " " + url.toFullString());
synchronized (listener) {
try {
listener.wait(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
} catch (InterruptedException e) {
}
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public void run() {
try {
while (!shutdown) {
synchronized (this) {
wait(HTTPCLIENTCONNECTIONMANAGER_CLOSEWAITTIME_MS);
for (PoolingHttpClientConnectionManager connectionManager : connectionManagers) {
connectionManager.closeExpiredConnections();
connectionManager.closeIdleConnections(HTTPCLIENTCONNECTIONMANAGER_CLOSEIDLETIME_S, TimeUnit.SECONDS);
}
}
}
} catch (InterruptedException ex) {
shutdown();
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public void run() {
try {
while (!shutdown) {
synchronized (this) {
wait(HTTPCLIENTCONNECTIONMANAGER_CLOSEWAITTIME_MS);
for (PoolingHttpClientConnectionManager connectionManager : connectionManagers) {
connectionManager.closeExpiredConnections();
connectionManager.closeIdleConnections(HTTPCLIENTCONNECTIONMANAGER_CLOSEIDLETIME_S, TimeUnit.SECONDS);
}
}
}
} catch (InterruptedException ex) {
shutdown();
}
}
代码示例来源:origin: apache/kafka
private synchronized void maybeAwaitWakeup() {
try {
int remainingBlockingWakeups = numBlockingWakeups;
if (remainingBlockingWakeups <= 0)
return;
while (numBlockingWakeups == remainingBlockingWakeups)
wait();
} catch (InterruptedException e) {
throw new InterruptException(e);
}
}
内容来源于网络,如有侵权,请联系作者删除!