public class ProfilingReentrantLock
extends java.lang.Object
implements java.util.concurrent.locks.Lock
ReentrantLock and profiles the time
it takes a thread to acquire the lock, and the time for which the lock is held.
When a thread calls unlock() then these times are printed, together with the code location
which used the lock.
This lock can be used as an alternative to "synchronized" blocks, when we want to detect lock contention.
It may also be used as an alternative to some other Lock, although at the moment only methods Lock.lock()
and Lock.unlock() are implemented. For the other Lock methods we throw UnsupportedOperationException,
but it should be easy enough to also implement them when needed.
This class is added to jmanager for work on http://jira.alma.cl/browse/COMP-6488. Later it should be moved to module jacsutil.
| Modifier and Type | Field and Description |
|---|---|
static boolean |
isProfilingEnabled |
static java.lang.String |
PROFILING_ENABLED_PROPERTYNAME |
| Constructor and Description |
|---|
ProfilingReentrantLock(java.lang.String lockName) |
| Modifier and Type | Method and Description |
|---|---|
static java.util.concurrent.locks.Lock |
createReentrantLock(java.lang.String lockName)
Factory method that encapsulates the checking of property
PROFILING_ENABLED_PROPERTYNAME
and the corresponding creation of either a ProfilingReentrantLock or a ReentrantLock. |
void |
lock() |
void |
lockInterruptibly() |
java.util.concurrent.locks.Condition |
newCondition() |
boolean |
tryLock() |
boolean |
tryLock(long timeout,
java.util.concurrent.TimeUnit unit) |
void |
unlock() |
public static final java.lang.String PROFILING_ENABLED_PROPERTYNAME
public static final boolean isProfilingEnabled
public static java.util.concurrent.locks.Lock createReentrantLock(java.lang.String lockName)
PROFILING_ENABLED_PROPERTYNAME
and the corresponding creation of either a ProfilingReentrantLock or a ReentrantLock.
We return only the base type "Lock" to keep the implementation of ProfilingReentrantLock simple for the time being. Some methods of ReentrantLock are final, so that delegation anyway is easier than subtyping. If we really need the additional methods, we could refactor ProfilingReentrantLock to inherit from ReentrantLock and change the return type to ReentrantLock.
lockName - Only used for the profiling variant, for log output.public void lock()
lock in interface java.util.concurrent.locks.Lockpublic void lockInterruptibly()
throws java.lang.InterruptedException
lockInterruptibly in interface java.util.concurrent.locks.Lockjava.lang.InterruptedExceptionpublic boolean tryLock()
tryLock in interface java.util.concurrent.locks.Lockpublic boolean tryLock(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
tryLock in interface java.util.concurrent.locks.Lockjava.lang.InterruptedExceptionpublic void unlock()
unlock in interface java.util.concurrent.locks.Lockpublic java.util.concurrent.locks.Condition newCondition()
newCondition in interface java.util.concurrent.locks.Lock