List of utility methods to do ReentrantLock
Lock | getActivityLock() get Activity Lock return activityLock;
|
ReentrantLock | getAudioLock() get Audio Lock return audioLock;
|
Lock | getLock(String id) get Lock synchronized (idToLockMap) { Lock lock = idToLockMap.get(id); if (lock == null) { lock = new ReentrantLock(); idToLockMap.put(id, lock); return lock; |
String | getLockInfo(ReentrantLock lock) get Lock Info String lockid = "Lock@" + Integer.toHexString(lock.hashCode()); return "lock " + lockid + " held=" + lock.getHoldCount() + " isHeldMe=" + lock.isHeldByCurrentThread() + " hasQueueThreads=" + lock.hasQueuedThreads(); |
boolean | isRepair() is Repair return updateLock.isHeldByCurrentThread();
|
boolean | lock() lock lock.lock();
locked = true;
return locked;
|
void | readSyncLock(String id) read Sync Lock if (lockPool.containsKey(id)) {
lockPool.get(id).lock();
|
void | removeJavaStdLoggerHandlers() 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(); |
void | runConcurrent(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 { ... |
void | runUnderLock(ReentrantLock lock, Runnable runnable) Run given runnable under given lock lock.lock(); try { runnable.run(); } finally { lock.unlock(); |