Possible file descriptor leakage in RandomAccessFile

Florian Weimer fweimer at bfk.de
Tue Jun 9 07:03:43 PDT 2009


* Robert Larsen:

> But with lots of logging the servers crash with too many open files and
> listing the open files in /proc/pid/fd (this is on Linux) I can see
> hundreds of open log files. That shouldn't be the case so I dumped the
> memory of the Java process and looked at it through 'jhat'. Only one
> instance of RandomAccessFile as I expected.

Did you dump only the live subset of the heap, perhaps?

In general, you cannot rely on the garbage collector to free native
resources (such as file descriptors) in a timely manner.  If you
allocate them at a high rate (or don't know the rate beforehand), you
really must free those resources manually (by closing the files
explicitly, in your case).

> This is with 1.6.0_12 on a 64 bit system.

Isn't nio-dev the wrong list for that?  (I really don't understand
Sun's reluctance to provide general user mailing lists for (Open)JDK,
though.)

-- 
Florian Weimer                <fweimer at bfk.de>
BFK edv-consulting GmbH       http://www.bfk.de/
Kriegsstraße 100              tel: +49-721-96201-1
D-76133 Karlsruhe             fax: +49-721-96201-99



More information about the nio-dev mailing list