title: How to wait until a lock is released in another thread in Java?
body: <p>I am trying to figure out how can we correctly wait until a lock is released in another thread.</p>
  
  <p>I think the code will explain better what do I mean:</p>
  
  <pre><code>myLock.lock();
  sendSomewhereMyLock(myLock); //creates new threads inside
  myLock.waitUntilReleasedByAnotherThread(60L, TimeUnit.SECONDS);
  //do something after the lock is released
  </code></pre>
  
  <p>I thought that <code>tryLock(long time, TimeUnit unit)</code> is the method which I need, but Java docs says that the method will be executed immediately because the lock was acquired by current thread:</p>
  
  <blockquote>
    <p>If the lock is available this method returns immediately with the
    value true. If the lock is not available then the current thread
    becomes disabled for thread scheduling purposes and lies dormant until
    one of three things happens:</p>
    
    <ul>
    <li>The lock is acquired by the current thread; or  </li>
    <li>Some other thread interrupts the current thread, and interruption of lock acquisition is supported; or </li>
    <li>The specified waiting time elapses</li>
    </ul>
  </blockquote>
  
  <p>What should I use then?</p>