Hi all,
It would seem the documentation around using an AccessTimeout of 0 is a
bit screwy.
I think it would only disallowed concurrent access if it is used in
conjunction with a Lock WRITE. If used with a Lock READ it should simply
go through a read lock and invoke the instance as per David's pseudo
code from 2009. :-)
On 07/30/2009 12:48 AM, David Blevins wrote:
> Here's some boiler plate implementation code to illustrate:
>
> TimeUnit unit = ..//;
> long timeout = ..//;
> boolean concurrencyNotAllowed = ..//;
>
> Lock statefulInstanceLock = ..//;
>
> boolean noWait = timeout == 0 || concurrencyNotAllowed;
>
> if (noWait) {
> if (statefulInstanceLock.tryLock()) {
> // invoke instance
> } else {
> // instance in use
> if (concurrencyNotAllowed) throw new
> ConcurrentAccessException("Instance is in use, no wait was attempted");
> else throw new ConcurrentAccessTimeoutException("Instance
> is in use, no wait was attempted");
> }
> } else {
> if (statefulInstanceLock.tryLock(timeout, unit)) {
> // invoke instance
> } else {
> throw new ConcurrentAccessTimeoutException("Instance is in
> use. Waited for " + timeout + " " + unit);
> }
> }
So if nobody objects I'll file an issue to adjust this.
Carlo