“Too many open files” error on Ubuntu

So, you’ve run into a “Too many open files” error (why else would you be here?)
I ran into it on some Ubuntu Hardy systems where Tomcat was running and Java had been allocated a ton of memory (thus giving it plenty of space to run out of control.)

It’s a simple fix.
Add increased limits to /etc/security/limits.conf. Here’s what I added to fix my problem:

* soft nofile 16384
* hard nofile 16384

… then edit /etc/pam.d/common-session and add:

session required pam_limits.so

to the bottom of the file. Users will have to re-login to see the new limits.