ReentrantLock isLocked - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for ReentrantLock isLocked method.

This code example shows how to use the following methods:isLocked, lock, unlock
package de.unisb.cs.st.javalanche.mutation.bytecodeMutations.replaceThreadCalls.classes; 
 
import java.util.concurrent.locks.ReentrantLock;
 
public class LockUnlockTEMPLATE { 
 
	int counter = 1;
 
	public boolean m1() { 
		ReentrantLock lock = new ReentrantLock();
		lock.lock(); 
		try { 
			counter++;
		} finally { 
			lock.unlock();
		} 
		return lock.isLocked();
	} 
} 

9
CodeRank
This code example shows how to use the following methods:isLocked
      } 
    } 
  } 
 
  public boolean isLocked() { 
    return lock.isLocked();
  } 
} 
7
CodeRank
This code example shows how to use the following methods:isLocked
        lock.unlock();
    } 
 
    @Override 
    public boolean isLocked() { 
        return lock.isLocked();
    } 
 
    @Override 
    public Thread getOwner() {
        return owner;
    } 
 
    @Override 
    public boolean isLockedByOtherThread() { 
        return lock.isLocked() && !lock.isHeldByCurrentThread();
    } 
 
    @Override 
    public boolean isOwner(final Thread thread) {
7
CodeRank
This code example shows how to use the following methods:isHeldByCurrentThread, isLocked, unlock
    } 
 
    @Override 
    public boolean unlock() { 
        verifyConversationContextActive(); 
        if (!concurrencyLock.isLocked()) {
            return true; 
        } 
        if (concurrencyLock.isHeldByCurrentThread()) {
            concurrencyLock.unlock();
            ConversationLogger.LOG.conversationUnlocked(this);
        } else { 
            ConversationLogger.LOG.illegalConversationUnlockAttempt(this, "not owner");
        } 
        return !concurrencyLock.isLocked();
    } 
 
    private void verifyConversationContextActive() { 
        if (!isContextActive()) { 
            throw new ContextNotActiveException("Conversation Context not active when method called on conversation " + this);
6
CodeRank
This code example shows how to use the following methods:isLocked
  /** 
   * Returns whether this monitor is occupied by any thread. This method is designed for use in 
   * monitoring of the system state, not for synchronization control. 
   */ 
  public boolean isOccupied() { 
    return lock.isLocked();
  } 
 
  /** 
   * Returns whether the current thread is occupying this monitor (has entered more times than it 
   * has left). 
   */ 
  public boolean isOccupiedByCurrentThread() { 
    return lock.isHeldByCurrentThread();
  } 
 
  /** 
   * Returns the number of times the current thread has entered this monitor in excess of the number 
   * of times it has left. Returns 0 if the current thread is not occupying this monitor. 
   */ 
7
CodeRank
This code example shows how to use the following methods:isLocked, lock, unlock
package de.unisb.cs.st.javalanche.mutation.bytecodeMutations.replaceThreadCalls.classes; 
 
import java.util.concurrent.locks.ReentrantLock; 
 
public class LockUnlockTEMPLATE { 
 
	int counter = 1;
 
	public boolean m1() { 
		ReentrantLock lock = new ReentrantLock();
		lock.lock(); 
		try { 
			counter++;
		} finally { 
			lock.unlock();
		} 
		return lock.isLocked();
	} 
} 

7
CodeRank
This code example shows how to use the following methods:isLocked
  /** 
   * Returns whether this monitor is occupied by any thread. This method is designed for use in 
   * monitoring of the system state, not for synchronization control. 
   */ 
  public boolean isOccupied() { 
    return lock.isLocked();
  } 
 
  /** 
   * Returns whether the current thread is occupying this monitor (has entered more times than it 
   * has left). 
   */ 
  public boolean isOccupiedByCurrentThread() { 
    return lock.isHeldByCurrentThread();
  } 
 
  /** 
   * Returns the number of times the current thread has entered this monitor in excess of the number 
   * of times it has left. Returns 0 if the current thread is not occupying this monitor. 
   */ 
6
CodeRank
This code example shows how to use the following methods:isLocked, lock
  private static boolean isInitialized = false;
 
  // Create the lock if there is no lock 
  private synchronized static void initialize() { 
    if (!isInitialized) {
      trafficLock = new ReentrantLock();
      isInitialized = true;
    } 
  } 
 
  // Acquire the traffic lock to block Checkin activity 
  public static synchronized boolean PauseTraffic() { 
    initialize(); 
    if (trafficLock.isLocked()) {
      return false; 
    } 
    trafficLock.lock();
    return true; 
  } 
 

5
CodeRank
This code example shows how to use the following methods:isLocked
  /** 
   * Returns whether this monitor is occupied by any thread. This method is designed for use in 
   * monitoring of the system state, not for synchronization control. 
   */ 
  public boolean isOccupied() { 
    return lock.isLocked();
  } 
 
  /** 
   * Returns whether the current thread is occupying this monitor (has entered more times than it 
   * has left). 
   */ 
  public boolean isOccupiedByCurrentThread() { 
    return lock.isHeldByCurrentThread();
  } 
 
  /** 
   * Returns the number of times the current thread has entered this monitor in excess of the number 
   * of times it has left. Returns 0 if the current thread is not occupying this monitor. 
   */ 
5
CodeRank
This code example shows how to use the following methods:isLocked, tryLock, unlock
        tts.speak(say, TextToSpeech.QUEUE_FLUSH, null);
    } 
 
    public void say(String say, OnUtteranceCompletedListener whenTextDone)
    { 
        if (waitForInitLock.isLocked())
        { 
            try 
            { 
                Log.d(D_LOG, "WAIT: WAIT INIT ");
                waitForInitLock.tryLock(180, TimeUnit.SECONDS);
            } 
            catch (InterruptedException e)
            { 
                Log.e(D_LOG, "interruped");
            } 
            //unlock it here so that it is never locked again 
            waitForInitLock.unlock();
            Log.d(D_LOG, "UNLOCK: (after waiting) WAIT INIT ");
        } 

5
CodeRank
isLocked Method Overview
Queries if this lock is held by any thread.
See Code Examples for other Java 8 ReentrantLock Methods: