Package nl.vpro.util.locker
Class ObjectLocker
java.lang.Object
nl.vpro.util.locker.ObjectLocker
- Author:
- Michiel Meeuwissen
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
static class
Most importantly this is a wrapper aroundReentrantLock
, but it stores some extra meta information, like the original key, thread, and initialization time. -
Field Summary
Modifier and TypeFieldDescription -
Method Summary
Modifier and TypeMethodDescriptionstatic List<ObjectLocker.LockHolder<? extends Serializable>>
static Map<Serializable,
ObjectLocker.LockHolder<? extends Serializable>> static void
listen
(ObjectLocker.Listener listener) You can registerObjectLocker.Listener
s for lock events, for logging or other reporting purposesstatic Predicate<StackTraceElement>
static void
unListen
(ObjectLocker.Listener listener) The reverse oflisten(Listener)
static <T> T
withKeyLock
(Serializable id, @NonNull String reason, @NonNull Runnable runnable) static <T> T
withKeyLock
(Serializable id, @NonNull String reason, @NonNull Callable<T> callable) static <T> T
withKeyLock
(Serializable id, @NonNull String reason, @NonNull Consumer<ObjectLocker.LockHolder<Serializable>> consumer, @NonNull Callable<T> callable) static <T,
K extends Serializable>
TwithObjectLock
(@Nullable K key, @NonNull String reason, @NonNull Callable<T> callable, @NonNull Map<K, ObjectLocker.LockHolder<K>> locks, @NonNull BiPredicate<Serializable, K> comparable) static <T,
K extends Serializable>
TwithObjectLock
(@Nullable K key, @NonNull String reason, @NonNull Consumer<ObjectLocker.LockHolder<K>> consumer, @NonNull Callable<T> callable, @NonNull Map<K, ObjectLocker.LockHolder<K>> locks, @NonNull BiPredicate<Serializable, K> comparable)
-
Field Details
-
summaryBiPredicate
-
-
Method Details
-
summaryPredicate
-
listen
You can registerObjectLocker.Listener
s for lock events, for logging or other reporting purposes -
unListen
The reverse oflisten(Listener)
-
getLockedObjects
-
withKeyLock
public static <T> T withKeyLock(Serializable id, @NonNull String reason, @NonNull Callable<T> callable) -
withKeyLock
public static <T> T withKeyLock(Serializable id, @NonNull String reason, @NonNull Consumer<ObjectLocker.LockHolder<Serializable>> consumer, @NonNull Callable<T> callable) -
withKeyLock
public static <T> T withKeyLock(Serializable id, @NonNull String reason, @NonNull Runnable runnable) -
withObjectLock
public static <T,K extends Serializable> T withObjectLock(@Nullable K key, @NonNull String reason, @NonNull Callable<T> callable, @NonNull Map<K, ObjectLocker.LockHolder<K>> locks, @NonNull BiPredicate<Serializable, K> comparable) - Parameters:
key
- The key to lock onreason
- A description for the reason of locking, which can be used in logging or exceptionslocks
- The map to hold the lockscomparable
- this determines whether two given keys are 'comparable'. If they are comparable, but different, and occurring at the same time, than this means that some code is locking different things at the same time, which may be a cause of deadlocks. If they are difference but also not comparable, then this remains unknown. We may e.g. be locking on a certain crid and on a mid. They are different, but it is not sure that they are actually about two different objects.
-
withObjectLock
public static <T,K extends Serializable> T withObjectLock(@Nullable K key, @NonNull String reason, @NonNull Consumer<ObjectLocker.LockHolder<K>> consumer, @NonNull Callable<T> callable, @NonNull Map<K, ObjectLocker.LockHolder<K>> locks, @NonNull BiPredicate<Serializable, K> comparable) -
currentLocks
- Since:
- 2.34
-