Skip to content

Too many files open

July 28, 2010
tags: ,

While analyzing the performance issues of a few applications I have often seen the problem of “Too many files open”. One linux/solaris machine using lsof command clearly indicates the process which is opening the file descriptors. Increase the max file handlers at OS level by defining a high number in /proc/sys/fs/file-max is a temporary solution to this issue.

Often the root cause has been connections not correctly closed. Example: either the ldap connection was not closed (properties for ldap pool not set) or file input or output stream not closed.

In apache Tomcat version 5.5.9 – in the class the issue is related to not closing the stream (absence of finally block):

public char[] getContents() {
                char[] result = null;
                try {
                    InputStreamReader isReader =
                        new InputStreamReader(new FileInputStream(sourceFile),
                    Reader reader = new BufferedReader(isReader);
                    if (reader != null) {
                        char[] chars = new char[8192];
                        StringBuffer buf = new StringBuffer();
                        int count;
                        while ((count =, 0, 
                                                    chars.length)) > 0) {
                            buf.append(chars, 0, count);
                        result = new char[buf.length()];
                        buf.getChars(0, result.length, result, 0);
                } catch (IOException e) {
                    log.error("Compilation error", e);
                return result;

This issue is corrected in the higher version of tomcat – i.e 5.5.30 and above.

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: