Activities

July 2013
M T W T F S S
« Jun   Aug »
1234567
891011121314
15161718192021
22232425262728
293031  

JVM : java.io.FileNotFoundException: (Too many open files)

Recently we had hit a rare error in one of the nodes in production. This error throws out from JVM and displayed through the Glassfish server.

This is because too many file descriptors’re opened by Glassfish. File descriptor can be limited in both system level and shell level.

To check maximum number of fd in system type ‘cat /proc/sys/fs/file-max’. In my case it is 65536. This is quite sufficient for current server setup.

[root@web04 ~]# cat /proc/sys/fs/file-max
65536

a. How to check current opened files limit ?

if you run the web server from root or diff. user account, Switch to that user account

[root@fc-web04 ~]# su - glassfish
[root@fc-web04 ~]# ulimit -Hn
1024
[root@fc-web04 ~]# ulimit -Sn
1024

Finding how many files are opened our java web server.

[root@web04 ~]# ps aux | grep "java" |awk '{ print $2}'|head -n1
15201
[root@web04 ~]# cd /proc/15201/fd
#you will be see a folder name created for process id under "/proc" folder
[root@web04 ~]# ls -la |wc -l
1027

So the value 1027 is exceed the default (1024) hard limit and hence applications got errors.

How to re-set ulimit

Edit the file limits.conf and added the following entries in it which respect to the user account you want to extend. Here I’m using Glassfish user account.

[root@web04 ~]# cat /etc/security/limits.conf | grep  "glassfish"
glassfish            soft    nofile            2048
glassfish            hard    nofile            2048
[root@web04 ~]#

Next you need to loggout the shell and re-check the ulimit value from the shell

[root@web04 ~]# ulimit -Hn
2048
[root@web04 ~]# ulimit -Sn
2048
[root@web04 ~]#

It’s updated to higher value and now you need to re-start the glassfish server to make it effect.

!! 🙂 Happy hours

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>