DERBY-4137 for details.
The fix has reduced the memory footprint, but in some rare cases the bug may still be observed. This is a function of transaction rate and timeout value. Using a lower timeout value may help.
As opposed to Java SE 5.0 or higher, there is no similar workaround for J2SE 1.4.