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.

Q

On 6/23/08, Tatu Saloranta <[EMAIL PROTECTED]> wrote:
> --- On Mon, 6/23/08, Quintin Beukes <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
>  For additional commands, e-mail: [EMAIL PROTECTED]
>
>


-- 
Quintin Beukes

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to