boolean gotMutex = impl.tryAcquireMutex();
boolean done = false;
+ int count = 0;
+ long startTime = 0;
while (!done) {
if (gotMutex || borrowMutex) {
runWithMutex();
done = true;
} else {
- LOGGER.warn("Retry mutex acquire");
+ if (count % 10 == 0) {
+ // Taking too long, sleep for a while.
+ LOGGER.warn("Retry mutex acquire");
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e) {
+ }
+ }
gotMutex = impl.tryAcquireMutex();
+ long currentTime = System.currentTimeMillis();
+ if ((currentTime - startTime) > 10) {
+ startTime = currentTime;
+ count++;
+ }
}
}