Hi,
I encountered a bug in the Timer class. In the remove method, when the heap
needs to be shrunk, there is a line of code missing. It needs to assign the
newly created heap to the instance variable that contained the old heap.
Once this happens, every subsequent remove causes the heap to attempt
resize.
Here is the diff:
diff -r1.2 -r1.3
127a128
> heap = new_heap;
Here is the old remove() method and the new one to make it clear:
// old
private void remove()
{
// clear the entry first
heap[elements] = null;
elements--;
if (elements + DEFAULT_SIZE / 2 <= (heap.length / 4))
{
TimerTask new_heap[] = new TimerTask[heap.length / 2];
System.arraycopy(heap, 0, new_heap, 0, elements + 1);
}
}
// new
private void remove()
{
// clear the entry first
heap[elements] = null;
elements--;
if (elements + DEFAULT_SIZE / 2 <= (heap.length / 4))
{
TimerTask new_heap[] = new TimerTask[heap.length / 2];
System.arraycopy(heap, 0, new_heap, 0, elements + 1);
heap = new_heap;
}
}
Thanks,
Steve Mayer
Software Engineer
dynamicsoft, Inc
_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/classpath