Synchronization vs Lock

java.util.concurrent API provides a class called as Lock, which would basically serialize the control in order to access the critical resource. It gives method such as park() and unpark(). We can do similar things if we can use synchronized keyword and using wait() and notify() notifyAll() methods. I am wondering which one of these is … Read more

Is there a Mutex in Java?

See this page: http://www.oracle.com/technetwork/articles/javase/index-140767.html It has a slightly different pattern which is (I think) what you are looking for: try { mutex.acquire(); try { // do something } finally { mutex.release(); } } catch(InterruptedException ie) { // … } In this usage, you’re only calling release() after a successful acquire()