com.kuka.common.concurrent
Class PreemptiveLock

java.lang.Object
  extended by com.kuka.common.concurrent.PreemptiveLock

public class PreemptiveLock
extends Object

A reentrant lock class that allows to preempt and interrupt threads waiting for this lock.

This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

Constructor Summary
PreemptiveLock()
           
 
Method Summary
 void lockInterruptibly()
          Acquires the lock unless the current thread is interrupted.
 void preemptLock()
          Take the lock as soon as possible, while interrupting other threads waiting for this lock.
 boolean tryLock()
          Acquires the lock only if it is free at the time of invocation.
 boolean tryLock(long time, TimeUnit unit)
          Acquires the lock if it is free within the given waiting time and the current thread has not been interrupted.
 void unlock()
          Releases the lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PreemptiveLock

public PreemptiveLock()
Method Detail

preemptLock

public void preemptLock()
Take the lock as soon as possible, while interrupting other threads waiting for this lock.


lockInterruptibly

public void lockInterruptibly()
                       throws InterruptedException
Acquires the lock unless the current thread is interrupted.

Throws:
InterruptedException - the thread was interrupted while waiting for the lock
See Also:
Lock.lockInterruptibly()

tryLock

public boolean tryLock()
Acquires the lock only if it is free at the time of invocation.

Returns:
true if the lock was acquired
See Also:
Lock.tryLock()

tryLock

public boolean tryLock(long time,
                       TimeUnit unit)
                throws InterruptedException
Acquires the lock if it is free within the given waiting time and the current thread has not been interrupted.

Parameters:
time - the maximum time to wait for the lock
unit - the time unit
Returns:
true if the lock was acquired
Throws:
InterruptedException - the thread was interrupted while waiting for the lock
See Also:
Lock.tryLock(long, TimeUnit)

unlock

public void unlock()
Releases the lock.

See Also:
Lock.unlock()


Copyright © 2019. All rights reserved.