Skip to content

Tech Note 2

Randgalt edited this page Apr 18, 2012 · 2 revisions

InterProcessMutex acquire() can be used to return immediately if lock can’t be acquired.

Details

It’s not obvious from the docs, but calling InterProcessMutex.acquire(0, unit) will return immediately (i.e. without any waiting) if the lock cannot be acquired.

e.g.

InterProcessMutex lock = ...
boolean didLock = lock.acquire(0, TimeUnit.any);
if ( !didLock )
{
    // comes back immediately 
}
Clone this wiki locally