hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Quintin Beukes" <quin...@last.za.net>
Subject Re: isStale()
Date Mon, 23 Jun 2008 19:14:46 GMT
Actually yes.

Sometimes I truly think in crooked circles. My original impulse was
absolute, but I went around that to avoid the extra IF statement,
though it's there no matter what. The ABS would work the best and
perfectly given the MIN and MAX aren't both even or both odd. But even
if, the wrap is so rare, that it truly doesn't matter.

Q

On 6/23/08, Oleg Kalnichevski <olegk@apache.org> wrote:
> On Mon, 2008-06-23 at 20:48 +0200, Quintin Beukes wrote:
>  > Correction, ArrayIndexOutOfBounds exception.
>  >
>  > Eitherway,
>  > That should work much better. That protects against to much
>  > synchronization at the cost of possibly not distributing evenly, but
>  > that risk is so small, and not a big deal.
>  >
>  > At least you never goes out of index here.
>  >
>
>
> My bad. Of course, the overflow of the worker count can lead
>  to ArrayIndexOutOfBounds, which is not good. I think the fix suggested
>  by Tatu should be good enough. Alternatively we could just take an
>  absolute value of this.currentWorker++ % this.workerCount.
>
>  Math.abs(this.currentWorker++ % this.workerCount)
>
>  This should do the trick I believe.
>
>
>  Oleg
>
>
>
>  > Q
>  >
>  > On 6/23/08, Tatu Saloranta <cowtowncoder@yahoo.com> wrote:
>  > > --- On Mon, 6/23/08, Quintin Beukes <quintin@last.za.net> wrote:
>  > >
>  > >  ...
>  > >
>  > > > One can either modify the the method to either
>  > >  > (1) Implement a priority queue, which will give a perfect
>  > >  > distribution.
>  > >  > (2) Modify the method to do this:
>  > >  > int i;
>  > >  > synchronized (this)
>  > >  > {
>  > >  >   int i = this.currentWorker++ % this.workerCount;
>  > >  >   if (i == 0) this.currentWorker = 1;
>  > >
>  > >
>  > > How about rather:
>  > >
>  > >  if (++currentWorker < 0) { // overflow
>  > >   currentWorker = 0;
>  > >  }
>  > >  i = currentWorker % workerCount;
>  > >
>  > >  if goal is to protect against overflow (which I thought was the goal);
>  > >  or. I don't think our code helps against overflow itself.
>  > >  Or if one just wants to iterate over workers:
>  > >
>  > >  if (++currentWorker >= workerCount) {
>  > >   currentWorker = 0;
>  > >  }
>  > >  i = currentWorker % workerCount;
>  > >
>  > >  I doubt any of these really would make that much difference (including the
original code), but if one wants to be pedantic... :-)
>  > >
>  > >
>  > >  -+ Tatu +-
>  > >
>  > >
>  > >
>  > >
>  > >
>  > >
>  > >  ---------------------------------------------------------------------
>  > >  To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>  > >  For additional commands, e-mail: httpclient-users-help@hc.apache.org
>  > >
>  > >
>  >
>  >
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>  For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>


-- 
Quintin Beukes
Mime
View raw message