Code example for WeakHashMap

Methods: containsKey, get, put

0
  } 
   
   
  public synchronized ReentrantLock get(T val) {
    IdentityWrapper<T> key = IdentityWrapper.make(val);
    if (!_map.containsKey(key)) { _map.put(key, new ReentrantLock()); }
    return _map.get(key);
  } 
   
   
  public Runnable lock(T val) {
    final ReentrantLock l = get(val);
    Runnable result = new Unlocker(l);
    l.lock();
    return result;
  } 
   
   
  private static class Unlocker implements Runnable {
    private final ReentrantLock _l;
    public Unlocker(ReentrantLock l) { _l = l; }