Code example for Lock

Methods: locktryLockunlock

0
   * Like {@link #get()}, but when a value already exists, will only wait for the given amount of time before 
   * just proceeding to return the existing value instead of waiting for a new value to load. 
   */ 
  public V get(long timeout, TimeUnit timeUnit) {
    try { 
      if (lock.tryLock(timeout, timeUnit)) {
        try { 
          doGet(); 
        } finally { 
          lock.unlock();
        } 
      } 
      // timed out 
    } catch (InterruptedException ie) {
      // interrupted 
    } 
    V theValue = value;
    return theValue == null ? get() : theValue;
  } 
 
  /** 
   * @return object that is returned by the provided {@link Callable}. If not yet created, it will block and 
   *  wait for creation. If already created, it will return the existing value. The value will be re-created 
   *  periodically, if the object has been configured to, and when this is needed, this method will again 
   *  block while the value is re-created. 
   */ 
  public V get() { 
    lock.lock();
    try { 
      doGet(); 
    } finally { 
      lock.unlock();
    } 
    return value;
  } 
 
  private void doGet() { 
Contextual code suggestions in your IDE  Get Codota for Java