6

My OS is MacOs sierra, and I increase the maximum of opened files for each process using following commands and make them permanently affected:

$ sysctl kern.maxfiles
kern.maxfiles: 12288
$ sysctl kern.maxfilesperproc
kern.maxfilesperproc: 10240
$ sudo sysctl -w kern.maxfiles=1048600
kern.maxfiles: 12288 -> 1048600
$ sudo sysctl -w kern.maxfilesperproc=1048576
kern.maxfilesperproc: 10240 -> 1048576
$ ulimit -S -n
256
$ ulimit -S -n 1048576
$ ulimit -S -n

It indeed works when I use ulimit -a to see the limit in terminal.

However, When I run my Java server program, when then socket connection approach 5110,

"Too many open files Exception is still throw"

So I write following code to see the parameter of kernel when java running:

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);
}

And the result shows

open files                      (-n) 10240

It's very confused because I try to increase the limits everywhere I know.

* ~/.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'

Anyone can give me any hints about this question? Thanks a lot for you.

pyb1993
  • 125
  • 6
  • 1
    What is the real exception being thrown? – Joakim Danielson Aug 01 '18 at 06:37
  • The real exception is: java.io.FileNotFoundException: Too many open files – pyb1993 Aug 01 '18 at 12:11
  • Maybe [this](https://superuser.com/a/443168) could be helpful but the question you should ask yourself is why your program needs to have so many files open. – Joakim Danielson Aug 01 '18 at 13:10
  • thanks for your help, but I have already done this operation。 And serveral months ago, these parameters works for my server program written by C.But in java program, they doesn't work. – pyb1993 Aug 02 '18 at 09:01

0 Answers0