Java tutorial
//package com.java2s; /************************************************************************************** * Copyright (C) 2006-2015 EsperTech Inc. All rights reserved. * * http://www.espertech.com/esper * * http://www.espertech.com * * ---------------------------------------------------------------------------------- * * The software in this package is published under the terms of the GPL license * * a copy of which has been included with this distribution in the license.txt file. * **************************************************************************************/ import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantReadWriteLock; public class Main { private static String getLockInfo(ReentrantLock lock) { String lockid = "Lock@" + Integer.toHexString(lock.hashCode()); return "lock " + lockid + " held=" + lock.getHoldCount() + " isHeldMe=" + lock.isHeldByCurrentThread() + " hasQueueThreads=" + lock.hasQueuedThreads(); } private static String getLockInfo(ReentrantReadWriteLock lock) { String lockid = "RWLock@" + Integer.toHexString(lock.hashCode()); return lockid + " readLockCount=" + lock.getReadLockCount() + " isWriteLocked=" + lock.isWriteLocked(); } }