title: Is there a Mutex in Java?
body: <p>Is there a Mutex object in java or a way to create one?
  I am asking because a Semaphore object initialized with 1 permit does not help me.
  Think of this case:</p>
  
  <pre><code>try {
     semaphore.acquire();
     //do stuff
     semaphore.release();
  } catch (Exception e) {
     semaphore.release();
  }
  </code></pre>
  
  <p>if an exception happens at the first acquire, the release in the catch block will increase the permits, and the semaphore is no longer a binary semaphore.</p>
  
  <p>Will the correct way be? </p>
  
  <pre><code>try {
     semaphore.acquire();
     //do stuff
  } catch (Exception e) {
     //exception stuff
  } finally {
     semaphore.release();
  }
  </code></pre>
  
  <p>Will the above code ensure that the semaphore will be binary?</p>