class GuardedObject<T>{ //持有受保护的对象 T obj; final Lock lock = new ReentrantLock(); final Condition done =lock.newCondition(); final int timeout=2; //保存所有GuardedObject final static Map<Object, GuardedObject> gos=new ConcurrentHashMap<>(); //静态方法创建GuardedObject static <K> GuardedObject create(K key){ GuardedObject go=new GuardedObject(); gos.put(key, go); return go; }