How to skip method if some thread owns by this method in java, i know that in .net exists Monitor.TryEnter, and i can accomplish that by something like this:
if(Monitor.TryEnter()){
//do work
}
//else skip
But how can i accomplish that behavior in java, is any equivalent of Monitor.TryEnter in java.
Would
ReentrantLock#tryLock()work for you?It has the behavior that you want, but it requires an explicit lock object and as such it does not work with the embedded Java object monitor – I do not believe that there is an equivalent to
tryLock()for Java object monitors.