Java Utililty Methods Thread Lock

List of utility methods to do Thread Lock

Description

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

Method

ClassloadClassWithRegisteredClassLoaders(String className)
Loads a class with the reigistered class loaders.
if (className == null) {
    throw new ClassNotFoundException("Class name is null!");
LOCK.readLock().lock();
try {
    if (CLASSLOADER_MAP == null) {
        throw new ClassNotFoundException();
    for (Map<String, ClassLoader> clm : CLASSLOADER_MAP.values()) {
        for (Map.Entry<String, ClassLoader> cle : clm.entrySet()) {
            if (cle.getKey().equals(className)) {
                return loadClass(className, cle.getValue());
    throw new ClassNotFoundException();
} finally {
    LOCK.readLock().unlock();
voidlock(Lock lock)
Simply locks passed Lock object
lock.lock();
voidlock(Lock lock)
lock
if (lock != null) {
    lock.lock();
StacklockAll(List locks)
lock All
Stack<Lock> lockedLocks = new Stack<Lock>();
for (Lock lock : locks) {
    if (lock.tryLock()) {
        lockedLocks.push(lock);
    } else {
        break;
return lockedLocks;
voidlockedSleep(Lock l, long time)
Releases l before sleeping and then acquires l after sleeping.
l.unlock();
try {
    Thread.sleep(time);
} catch (InterruptedException ex) {
    Thread.currentThread().interrupt();
} finally {
    l.lock();
LinkedBlockingDequenewLinkedBlockingDeque(Collection collection)
new Linked Blocking Deque
return collection != null ? new LinkedBlockingDeque<T>(collection) : new LinkedBlockingDeque<T>();
voidrelease()
release
_lock.release();
voidreleaseLock(final Lock lock)
release Lock
lock.unlock();
voidreleaseReadLock(final ReadWriteLock lock)
release Read Lock
releaseLock(lock.readLock());
voidrunSync(final Lock lock, final Runnable task)
Run task synchronously on current thread using provided lock for synchronization.
try {
    lock.lock();
    task.run();
} finally {
    lock.unlock();