Java 8 AbstractQueuedSynchronizer - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 AbstractQueuedSynchronizer class.

This code example shows how to use the following methods:tryAcquireNanos
	 * value. It it can't, the method return the false value 
	 */ 
	@Override 
	public boolean tryLock() { 
		try { 
			return sync.tryAcquireNanos(1, 1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
			return false; 
		} 
	} 
 
	/** 
	 * Method that try to acquire the lock. If it can, the method returns the true value. 
	 * If it can't, wait the time specified as parameter and if the lock hasn't been 
	 * released, it returns the false value. It the lock is released in that period of time, 
	 * the thread acquires the lock and the method returns the true value 
	 */ 
	@Override 
	public boolean tryLock(long time, TimeUnit unit)
4
CodeRank
This code example shows how to use the following methods:tryAcquireNanos
	} 
 
	@Override 
	public boolean tryLock() { 
		try{ 
			return sync.tryAcquireNanos(1, 1000);
		}catch(InterruptedException e){
			e.printStackTrace();
			return false; 
		} 
	} 
 
	@Override 
	public boolean tryLock(long time, TimeUnit unit)
			throws InterruptedException { 
		return sync.tryAcquireNanos(1, TimeUnit.NANOSECONDS.convert(time, unit));
	} 
 
	@Override 
	public void unlock() { 
4
CodeRank
This code example shows how to use the following methods:tryAcquireSharedNanos
  /** 
   * Waits for the {@code waitDuration} until the circuit has been closed, aborting if interrupted, 
   * returning true if the circuit is closed else false. 
   */ 
  public boolean await(Duration waitDuration) throws InterruptedException {
    return sync.tryAcquireSharedNanos(0, waitDuration.toNanos());
  } 
 
  /** 
   * Closes the circuit, releasing any waiting threads. 
   */ 
  public void close() { 
    sync.releaseShared(1);
  } 
 
  /** 
   * Interrupts waiting threads. 
   */ 
  public void interruptWaiters() { 
    for (Thread t : sync.getSharedQueuedThreads())
3
CodeRank
This code example shows how to use the following methods:acquireInterruptibly
	@Test(expected = CPUReactiveAuditException.class)
	public void acquireInterruptibly() 
			throws InterruptedException
	{ 
        TestTools.strict.commit(); 
		c.acquireInterruptibly(1);
	} 
 
	@Test(expected = CPUReactiveAuditException.class)
	public void acquireShared() 
			throws InterruptedException
	{ 
        TestTools.strict.commit(); 
		c.acquireShared(1);
	} 
 
	@Test(expected = CPUReactiveAuditException.class)
	public void acquireSharedInterruptibly() 
			throws InterruptedException
3
CodeRank
See Code Examples for Java 8 AbstractQueuedSynchronizer Methods: