MacOs: increase maximum of opened files doesn't work for java program
Asked Answered
H

0

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.

Hylomorphism answered 1/8, 2018 at 6:28 Comment(4)
What is the real exception being thrown?Baroscope
The real exception is: java.io.FileNotFoundException: Too many open filesHylomorphism
Maybe this could be helpful but the question you should ask yourself is why your program needs to have so many files open.Baroscope
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.Hylomorphism

© 2022 - 2024 — McMap. All rights reserved.