[PJUG Javamail] What causes "Too many open files" in Tomcat
Wayne Carstensen
waynec at c-ware.com
Wed Nov 4 14:13:45 EST 2009
I don't know if this applies to your problem, but we have had similar
issues with some libraries not explicitly closing file resources. They
are expecting that a garbage collection will .close() the file resource
when the owing object goes out of scope (in your case
/usr/dict/wordlist.pwd). I can only assume this is because they have the
.close() sitting in a finalize() method.
In our case, the 'too many files open' occurs when we are opening
numerous files briefly to calculate the checksums or gather values from
thousands of files. For the simple cases we forced the garbage collector
to run with a System.gc(); This is not entirely reliable since there is
no guarantee that gc will do any work. In a severe case we were forced
to limit the amount of memory available to the JVM to encourage garbage
collection early and often so that file handles would be released.
Needless to say it was a joy to find the right -Xmx value that was low
enough to encourage enough gc() and large enough to complete the task!
If I recall, the major offender was the Byte Code Engineering Library
(BCEL).
If the process is highly repetitious, like a pounding from a test loop
or simply heavy traffic, this would be an indication that the system has
been unable to release the file resources timely. The use of
SurvivorRatio=8 in the recommended JVM parms may be trying to speak to
this issue since the default is 25.
To debug this, I would look for ways to insert strategic thread sleeps
and gc() calls to see if the problem is delayed (as in more successful
iterations) or averted altogether. If either of these approaches work,
my condolences. It may require the added chore of explicitly setting
variables to null to encourage more thorough minor garbage collections.
Since this message is coming from Tomcat activities, your hands are
definitely tied.
Good luck Rob.
- Wayne
Wayne Carstensen
C-Ware, Inc.
Rob Tanner wrote:
> Hi,
>
> I’m getting messages like these in the catalina.out log:
>
> java.net.SocketException: Too many open files
> java.io.FileNotFoundException: /usr/dict/wordlist.pwd (Too many open
> files)
> java.io.FileNotFoundException:
> /var/apache/apache-tomcat-5.5.23/webapps/AccountManager/WEB-INF/classes/log4j.properties
> (Too many open files)
> java.net.SocketException: Too many open files
>
>
>
> And, of course, I have to stop and restart Tomcat to get it to work
> again. This is not a system error; it’s only in Tomcat. I did some
> googling and found a suggestion with regard to Java arguments when
> Tomcat starts up.
>
> These are the options I’m starting Tomcat with: '-XX:NewSize=128m
> -XX:MaxNewSize=128m -XX:SurvivorRatio=8 -Xms256m -Xmx512m'
>
> I’ve also gone through the most active apps and made sure that I was not
> leaving any database or LDAP connections open.
>
> Any ideas?
>
> Thanks,
> Rob
>
>
>
> *Rob Tanner
> *JAVA Developer
> Linfield College, McMinnville Oregon
More information about the Javamail
mailing list