Java Utililty Methods ReentrantLock

List of utility methods to do ReentrantLock

Description

The list of methods to do ReentrantLock are organized into topic(s).

Method

LockgetActivityLock()
get Activity Lock
return activityLock;
ReentrantLockgetAudioLock()
get Audio Lock
return audioLock;
LockgetLock(String id)
get Lock
synchronized (idToLockMap) {
    Lock lock = idToLockMap.get(id);
    if (lock == null) {
        lock = new ReentrantLock();
        idToLockMap.put(id, lock);
    return lock;
StringgetLockInfo(ReentrantLock lock)
get Lock Info
String lockid = "Lock@" + Integer.toHexString(lock.hashCode());
return "lock " + lockid + " held=" + lock.getHoldCount() + " isHeldMe=" + lock.isHeldByCurrentThread()
        + " hasQueueThreads=" + lock.hasQueuedThreads();
booleanisRepair()
is Repair
return updateLock.isHeldByCurrentThread();
booleanlock()
lock
lock.lock();
locked = true;
return locked;
voidreadSyncLock(String id)
read Sync Lock
if (lockPool.containsKey(id)) {
    lockPool.get(id).lock();
voidremoveJavaStdLoggerHandlers()
remove Java Std Logger Handlers
ReentrantLock lock = new ReentrantLock();
try {
    lock.lock();
    Logger globalLogger = Logger.getLogger("net.jxta");
    Handler[] handlers = globalLogger.getHandlers();
    for (Handler handler : handlers) {
        System.out.println("HANDLER=" + handler);
} catch (Exception e) {
} finally {
    if (!lock.isLocked())
        lock.unlock();
voidrunConcurrent(long startGapTime, Runnable... tasks)
Run multiple tasks concurrently and wait until all are finished.
final ReentrantLock lock = new ReentrantLock();
final Condition started = lock.newCondition();
ArrayList<Thread> threads = new ArrayList<>(tasks.length);
for (Runnable task : tasks) {
    threads.add(new Thread(new Runnable() {
        @Override
        public void run() {
            try {
...
voidrunUnderLock(ReentrantLock lock, Runnable runnable)
Run given runnable under given lock
lock.lock();
try {
    runnable.run();
} finally {
    lock.unlock();