Java Code Examples for java.util.concurrent.locks.LockSupport.parkUntil()

The following are Jave code examples for showing how to use parkUntil() of the java.util.concurrent.locks.LockSupport class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Reactive4JavaFlow   File: SpscCountDownLatch.java   View Source Code Vote up 6 votes
public final boolean await(long time, TimeUnit unit) throws InterruptedException {
    if (WAITER.compareAndSet(this, null, Thread.currentThread())) {
        long deadline = System.currentTimeMillis() + unit.toMillis(time);
        for (;;) {
            LockSupport.parkUntil(deadline);
            if (Thread.interrupted()) {
                throw new InterruptedException();
            }
            if (WAITER.getAcquire(this) == this) {
                return true;
            }
            if (System.currentTimeMillis() >= deadline) {
                return false;
            }
        }
    }
    return true;
}
 
Example 2
Project: CustomLogger   File: NSLoggerClient.java   View Source Code Vote up 5 votes
private void startLoggingThreadIfNeeded()
{
	try
	{
		boolean waiting = false;
		if (loggingThread == null)
		{
			synchronized (this)
			{
				if (loggingThread == null)
				{
					loggingThread = new LoggingWorker();
					loggingThread.readyWaiters.add(Thread.currentThread());
					loggingThread.start();
					waiting = true;
				}
			}
		}
		while (!loggingThread.ready.get())
		{
			if (!waiting)
			{
				loggingThread.readyWaiters.add(Thread.currentThread());
				waiting = true;
			}
			LockSupport.parkUntil(this, System.currentTimeMillis() + 100);
			if (Thread.interrupted())
				Thread.currentThread().interrupt();
		}
	}
	catch (Exception e)
	{
		Log.e("NSLogger", "Exception caught in startLoggingThreadIfNeeded: " + e.toString());
	}
}
 
Example 3
Project: openjdk-jdk10   File: LockSupportTest.java   View Source Code Vote up 4 votes
void park(long millis) {
    LockSupport.parkUntil(deadline(millis));
}
 
Example 4
Project: openjdk-jdk10   File: LockSupportTest.java   View Source Code Vote up 4 votes
void park(long millis) {
    LockSupport.parkUntil(theBlocker(), deadline(millis));
}