Re: Using a certain percentage of the JVM storage
Stefan Ram wrote:
Eric Sosman <Eric.Sosman@sun.com> writes:
An appliation should use a certain percentage (approximately)
of the data storage area of its JVM for output file buffers.
If the buffers ever hold more data than this, they are to be
from totalMemory() to estimate "memory in use," and subtract that
from maxMemory() to estimate "memory potentially available." Deduct
a fudge factor for classes yet to be loaded and objects yet to be
Thanks, I wonder whether it would make sense to use file
buffers which are linked only weakly. I have no experience
with weak references. But it would help if I would know that I
can rely on their finalizer being called when they are are
disposed. Then I could flush the buffers to their files
whenever one of them is being disposed by the memory reclaimer
or when the application ends.
I'm not an expert on finalization and associated stuff, but
the little I (think I) know makes me queasy about the idea. As
I understand it, there is no ironclad guarantee that all
garbage will be collected or even detected before the JVM exits,
hence no guarantee that finalizers will run, reference queues
will notify, and so on. You could wind up with some buffers
written and others not, leaving a file with gaps.
May I suggest stepping back from the trees a moment and
contemplating the forest? What is your purpose in postponing
the actual writes? Are you, maybe, bouncing around in a big
random-access file where you might write and overwrite the
same extents many times before the end? Something else? Tell
us about the goal, and maybe someone will suggest another way
to attain it.
--
Eric Sosman
esosman@ieee-dot-org.invalid