-
Bug
-
Resolution: Done
-
Minor
-
2.12
-
None
I have tried posting something to the blog at http://belaban.blogspot.com/2011/01/new-distributed-locking-service-in.html but it hasn't put up my comment yet, so I decided to create a JIRA as well.
I have taken the latest 2.12 build of Beta1 which includes the new LockService class. This class is so much of an improvement how the DistributedLockManager was; great work!
But anyways I found that when you try to acquire a lock with a wait, it is not converting the timeunits correctly unless it is in MILLISECONDS. This cannot be reproduced with the demo class since it always uses MILLISECONDS.
The code in question is found on the Locking$ClientLock inner class.
public boolean tryLock(long time, TimeUnit unit) throws InterruptedException { return acquireTryLock(unit.convert(time, TimeUnit.MILLISECONDS), true); }
The way this is, the code will convert the time value passed in as MILLISECONDS to the passed in TimeUnit. This simply needs to change to make the TimeUnit.MILLISECONDS the object of which the convert method is being called on and having unit as the second argument.
public boolean tryLock(long time, TimeUnit unit) throws InterruptedException { return acquireTryLock(TimeUnit.MILLISECONDS.convert(time, unit), true); }
This obviously has a simple workaround of always passing in a TimeUnit of MILLISECONDS and having the time value already adjusted.
And again this new feature looks to be very promising.
Also when just checking the jgroups code base there are 3 other references to convert, 2 of which are also broken in this fashion.
HashedTimingWheel.schedule
TimeScheduler2.schedule
Both of these references in the jgroup code base are always passed MILLISECONDS, so it would only be seen if client code were to interact with them somehow.