title: Too many open files ( ulimit already changed )
body: <p>I'm working on a debian server with tomcat 7 and java 1.7. This is an application that recieves several TCP connections, each TCP connection is an open file by the java process.</p>
  
  <p>Looking at <code>/proc/pid of java/fd</code> I found that, sometimes, the number of open files exceeds 1024, when this happens, I find in <code>catalina.out</code> log the stacktrace <code>_SocketException: Too many open files_</code></p>
  
  <p>Everything I find about this error, people refer to the ulimit, I have already changed this thing and the error keeps happening. Here is the config:</p>
  
  <p>at <code>/etc/security/limits.conf</code></p>
  
  <pre><code>root    soft    nofile  8192
  root    hard    nofile  8192
  </code></pre>
  
  <p>at <code>/etc/sysctl.conf</code></p>
  
  <pre><code>fs.file-max = 300000
  </code></pre>
  
  <p>the <code>ulimit -a</code> command returns:</p>
  
  <pre><code>core file size          (blocks, -c) 0
  data seg size           (kbytes, -d) unlimited
  scheduling priority             (-e) 0
  file size               (blocks, -f) unlimited
  pending signals                 (-i) 16382
  max locked memory       (kbytes, -l) 64
  max memory size         (kbytes, -m) unlimited
  open files                      (-n) 8192
  pipe size            (512 bytes, -p) 8
  POSIX message queues     (bytes, -q) 819200
  real-time priority              (-r) 0
  stack size              (kbytes, -s) 8192
  cpu time               (seconds, -t) unlimited
  max user processes              (-u) unlimited
  virtual memory          (kbytes, -v) unlimited
  file locks                      (-x) unlimited
  </code></pre>
  
  <p>But, when I check the limits of the java process, it's only 1024</p>
  
  <p>at <code>/proc/pid of java/limits</code></p>
  
  <pre><code>Limit                     Soft Limit           Hard Limit           Units     
  Max cpu time              unlimited            unlimited            seconds   
  Max file size             unlimited            unlimited            bytes     
  Max data size             unlimited            unlimited            bytes     
  Max stack size            8388608              unlimited            bytes     
  Max core file size        0                    unlimited            bytes     
  Max resident set          unlimited            unlimited            bytes     
  Max processes             32339                32339                processes 
  Max open files            1024                 1024                 files     
  Max locked memory         65536                65536                bytes     
  Max address space         unlimited            unlimited            bytes     
  Max file locks            unlimited            unlimited            locks     
  Max pending signals       32339                32339                signals   
  Max msgqueue size         819200               819200               bytes     
  Max nice priority         0                    0                    
  Max realtime priority     0                    0                    
  Max realtime timeout      unlimited            unlimited            us        
  </code></pre>
  
  <p>How can I increase the number of <code>Max open files</code> for the java process?</p>