[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Bug fix for java.util.Timer replacement class
From: |
Steve Mayer |
Subject: |
Bug fix for java.util.Timer replacement class |
Date: |
Fri, 9 Feb 2001 17:19:09 -0500 |
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
- Bug fix for java.util.Timer replacement class,
Steve Mayer <=