On Wed, Oct 1, 2008 at 9:12 AM, Rob Heittman <[EMAIL PROTECTED]>wrote:
> As some folks found the CookieUtility class useful outside GPL context, I
> updated trunk to dedicate it to the public domain. Improvements/suggestions
> are welcome, maybe to inform a future Restlet feature along these lines.
>
Thank you for this, Rob.
I still have a nit with newUniqueID(): There's a race between
incr.getAndIncrement() and incr.set(0). Multiple threads could reach the
first statement, decide that lincr is indeed > Integer.MAX_VALUE and then
reach the second statement. Other threads could then see the same value more
than once.
Also, the range of lincr is not 0 .. 2^31, even without concurrency
problems, since at least one value > Integer.MAX_VALUE is always allowed.
How about something like this:
int lincr = nextNonNegative(incr); // lincr needn't be long now, rename?
...
private static int nextNonNegative(AtomicInteger a) {
while (true) {
int current = a.get();
int next = current == Integer.MAX_VALUE ? 0 : current + 1;
if (a.compareAndSet(current, next)) {
return current;
}
}
}
And some unrelated questions: Why does idToAlpha use double internally? Why
does it take a Number argument, when AFAICS it is only called on long
values?
--tim