title: MacOs: increase maximum of opened files doesn't work for java program
body: <p>My OS is MacOs sierra, and I increase the maximum of opened files for each process using following commands and make them permanently affected:</p>
  
  <pre><code>$ sysctl kern.maxfiles
  kern.maxfiles: 12288
  $ sysctl kern.maxfilesperproc
  kern.maxfilesperproc: 10240
  $ sudo sysctl -w kern.maxfiles=1048600
  kern.maxfiles: 12288 -&gt; 1048600
  $ sudo sysctl -w kern.maxfilesperproc=1048576
  kern.maxfilesperproc: 10240 -&gt; 1048576
  $ ulimit -S -n
  256
  $ ulimit -S -n 1048576
  $ ulimit -S -n
  </code></pre>
  
  <p><strong>It indeed works when I use <code>ulimit -a</code> to see the limit in terminal.</strong></p>
  
  <p>However, When I run my Java server program, when then socket connection approach 5110,</p>
  
  <p><strong>"Too many open files Exception is still throw"</strong></p>
  
  <p>So I write following code to see the parameter of kernel when java running：</p>
  
  <pre><code>String [] cmd={"/bin/bash","-c","ulimit -a"};
  Process proc = Runtime.getRuntime().exec(cmd);
  InputStream stderr = proc.getInputStream();
  InputStreamReader isr = new InputStreamReader(stderr);
  BufferedReader br = new BufferedReader(isr);
  String line;
  while ( (line = br.readLine()) != null) {
        System.out.println(line);
  }
  </code></pre>
  
  <p>And the result shows </p>
  
  <pre><code>open files                      (-n) 10240
  </code></pre>
  
  <p>It's very confused because I try to increase the limits everywhere I know.</p>
  
  <pre><code>* ~/.bash_profile: initialization for login (bash-)shells
  * ~/.bashrc: initialization for all interactive (bash-)shells
  * ~/.profile
  * /etc/bashrc: meant for functions and aliases
  * /etc/profile: all types of initialization scripts'
  </code></pre>
  
  <p>Anyone can give me any hints about this question?
  Thanks a lot for you.</p>