title: Why not using a try with lock in java?
body: <p>I've read <a href="https://stackoverflow.com/questions/6965731/are-locks-autocloseable">this topic</a>, and this <a href="http://www.java7developer.com/blog/?p=256" rel="nofollow noreferrer">blog article</a> about <em>try with resources</em> locks, as the question popped in my head.
  But actually, what I'd rather like would be a <em>try with lock</em>, I mean without lock instantiation. It would release us from the verbose 
  </p>
  
  <pre><code>lock.lock();
  try {
      //Do some synchronized actions throwing Exception 
  } finally {
      //unlock even if Exception is thrown
      lock.unlock();
  }
  </code></pre>
  
  <p>Would rather look like : 
  </p>
  
  <pre><code>? implements Unlockable lock ;
  ...
  try(lock) //implicitly calls lock.lock() 
  {
      //Do some synchronized actions throwing Exception 
  } //implicitly calls finally{lock.unlock();}
  </code></pre>
  
  <p>So <em>it would not be a TWR</em>, but just some boilerplate cleaning. </p>
  
  <p>Do you have any technical reasons to suggest describing <em>why</em> this would not be a reasonable idea? </p>
  
  <p>EDIT : to clarify the difference between what I propose and a simple <code>synchronized(lock){}</code> block, check this snippet :</p>
  
  <pre class="lang-java prettyprint-override"><code>import java.util.concurrent.locks.Condition;
  import java.util.concurrent.locks.ReentrantLock;
  
  
  public class Test {
  
          public static void main(String[] args) {
                  ReentrantLock locker =new ReentrantLock();
                  Condition condition = locker.newCondition();
                  Thread t1 = new Thread("Thread1") {
                          @Override
                          public void run(){
                                  synchronized(locker){
                                          try {
                                                  condition.await();
                                          } catch (InterruptedException e) {
                                                  Thread.currentThread().interrupt();
                                          }
                                          System.out.println("Thread1 finished");
                                  }
                          }
                  } ;
                  Thread t2 = new Thread("Thread2") {
                          @Override
                          public void run(){
                                  synchronized(locker){
                                          Thread.yield();
                                          condition.signal();
                                          System.out.println("blabla2");
                                  }
                          }
                  } ;
                  t1.start();
                  t2.start();
          }
  
  }
  </code></pre>
  
  <p>Execution will result in a <code>IllegalMonitorStateException</code>, so lock() and unlock() methods are not implicitly called within <code>synchronized</code> block.</p>