Package org.springframework.data.util
Interface Lock
public interface Lock
Lock provides more extensive locking operations than can be obtained using synchronized methods and
 Lock. It allows more flexible structuring and an improved usage model.
 
 This Lock abstraction is an extension to the lock utilities and intended for
 easier functional and try-with-resources usage.
 
 ReentrantLock backend = new ReentrantLock();
 Lock lock = Lock.of(backend);
 lock.executeWithoutResult(() -> {
   // callback without returning a result
 });
 lock.execute(() -> {
   // callback returning a result
   return …;
 });
 - Since:
- 3.2
- Author:
- Mark Paluch
- 
Nested Class SummaryNested ClassesModifier and TypeInterfaceDescriptionstatic interfaceAn acquired lock can be used with try-with-resources for easier releasing.
- 
Method SummaryModifier and TypeMethodDescriptiondefault <T> TExecute the action specified by the given callback object guarded by a lock and return its result.default voidexecuteWithoutResult(Runnable action) Execute the action specified by the given callback object guarded by a lock.lock()Acquires the lock.Acquires the lock unless the current thread is interrupted.static Lock
- 
Method Details- 
of- Parameters:
- delegate- must not be null.
- Returns:
- a new Lockadapter.
 
- 
lockLock.AcquiredLock lock()Acquires the lock.If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired. - See Also:
 
- 
lockInterruptiblyAcquires the lock unless the current thread is interrupted.Acquires the lock if it is available and returns immediately. If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens: - The lock is acquired by the current thread; or
- Some other thread interrupts the current thread, and interruption of lock acquisition is supported.
 If the current thread: - has its interrupted status set on entry to this method; or
- is interrupted while acquiring the lock, and interruption of lock acquisition is supported,
 InterruptedExceptionis thrown and the current thread's interrupted status is cleared.- Throws:
- InterruptedException
 
- 
executeExecute the action specified by the given callback object guarded by a lock and return its result. Theactionis only executed once the lock has been acquired.- Type Parameters:
- T- type of the result.
- Parameters:
- action- the action to run.
- Returns:
- the result of the action.
- Throws:
- RuntimeException- if thrown by the action
 
- 
executeWithoutResultExecute the action specified by the given callback object guarded by a lock. Theactionis only executed once the lock has been acquired.- Parameters:
- action- the action to run.
- Throws:
- RuntimeException- if thrown by the action.
 
 
-