Example usage for java.util.concurrent.locks ReentrantReadWriteLock toString

List of usage examples for java.util.concurrent.locks ReentrantReadWriteLock toString

Introduction

In this page you can find the example usage for java.util.concurrent.locks ReentrantReadWriteLock toString.

Prototype

public String toString() 

Source Link

Document

Returns a string identifying this lock, as well as its lock state.

Usage

From source file:com.sentaroh.android.TaskAutomation.TaskManager.java

final static private void acqRWLock(EnvironmentParms envParms, CommonUtilities util,
        ReentrantReadWriteLock lock, String id, int l_mode) {
    boolean l_r = false;
    //          Thread.dumpStack();
    String l_mode_string = id + " Write";
    if (l_mode == LOCK_MODE_READ)
        l_mode_string = id + " Read";

    if (l_mode == LOCK_MODE_READ)
        l_r = lock.readLock().tryLock();
    else/*from www. ja v  a  2  s  . c om*/
        l_r = lock.writeLock().tryLock();

    if (l_r) {
        if (envParms.settingDebugLevel >= 3) {
            util.addDebugMsg(3, "I", l_mode_string, " Lock acquired, Thread name=",
                    Thread.currentThread().getName());
        }
    } else {
        long b_time = System.currentTimeMillis();
        if (envParms.settingDebugLevel >= 2) {
            util.addDebugMsg(2, "I", l_mode_string, " Lock wait detected, Thread name=",
                    Thread.currentThread().getName() + ", Lock=" + lock.toString());
        }

        if (l_mode == LOCK_MODE_READ)
            lock.readLock().lock();
        else
            lock.writeLock().lock();

        if (envParms.settingDebugLevel >= 2) {
            util.addDebugMsg(2, "I", l_mode_string,
                    " Lock wait time=" + (System.currentTimeMillis() - b_time) + "(ms), Thread name=",
                    Thread.currentThread().getName());
        }
    }
}