日期:2014-05-20 浏览次数:20756 次
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
public class ObjectLockJudgement {
private static final ConcurrentHashMap<Object, Thread> relation = new ConcurrentHashMap<Object, Thread>();
/**
* @param args
*/
public static void main(String[] args) {
final int threadNumber = 100;
List<Object> lockers = new ArrayList<Object>(threadNumber);
for (int i = 0; i < threadNumber; i++) {
final Object locker = new Object();
lockers.add(locker);
new ThreadImpl(locker);
}
while (!relation.isEmpty()) {
for (final Object locker : lockers) {
final Thread t = relation.get(locker);
if (t != null)
System.out.println("the locker Object:" + locker.hashCode()