Refer to http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html
-XX:+MaxFDLimit Bump the number of file descriptors to max. (Relevant to Solaris only.)
Looking at the src code and strace the java process, the MaxFDLimit (default on) is applicable to Linux as well.
[root@javalab-linux64 3-6835686171]# ( ulimit -Hn2048 ; ulimit -Sn999; strace -f -v -o sleep-on.txt /usr/jdk1.6.0_38/bin/java -XX:+MaxFDLimit -Xmx64M -cp . Sleep 2 )
Sleep for 2s
[root@javalab-linux64 3-6835686171]# ( ulimit -Hn2048 ; ulimit -Sn999; strace -f -v -o sleep-off.txt /usr/jdk1.6.0_38/bin/java -XX:-MaxFDLimit -Xmx64M -cp . Sleep 2 )
Sleep for 2s
[root@javalab-linux64 3-6835686171]# grep NOFILE sleep-o*
sleep-on.txt:2952 getrlimit(RLIMIT_NOFILE, {rlim_cur=999, rlim_max=2*1024}) = 0
sleep-on.txt:2952 setrlimit(RLIMIT_NOFILE, {rlim_cur=2*1024, rlim_max=2*1024}) = 0
Sleep.java
public class Sleep {
public static void main(String args[]) {
System.out.println("Sleep for " + Integer.parseInt(args[0]) + "s ");
try {
Thread.sleep(Integer.parseInt(args[0])* 1000);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
-XX:+MaxFDLimit Bump the number of file descriptors to max. (Relevant to Solaris only.)
Looking at the src code and strace the java process, the MaxFDLimit (default on) is applicable to Linux as well.
[root@javalab-linux64 3-6835686171]# ( ulimit -Hn2048 ; ulimit -Sn999; strace -f -v -o sleep-on.txt /usr/jdk1.6.0_38/bin/java -XX:+MaxFDLimit -Xmx64M -cp . Sleep 2 )
Sleep for 2s
[root@javalab-linux64 3-6835686171]# ( ulimit -Hn2048 ; ulimit -Sn999; strace -f -v -o sleep-off.txt /usr/jdk1.6.0_38/bin/java -XX:-MaxFDLimit -Xmx64M -cp . Sleep 2 )
Sleep for 2s
[root@javalab-linux64 3-6835686171]# grep NOFILE sleep-o*
sleep-on.txt:2952 getrlimit(RLIMIT_NOFILE, {rlim_cur=999, rlim_max=2*1024}) = 0
sleep-on.txt:2952 setrlimit(RLIMIT_NOFILE, {rlim_cur=2*1024, rlim_max=2*1024}) = 0
Sleep.java
public class Sleep {
public static void main(String args[]) {
System.out.println("Sleep for " + Integer.parseInt(args[0]) + "s ");
try {
Thread.sleep(Integer.parseInt(args[0])* 1000);
}
catch (Exception e) {
e.printStackTrace();
}
}
}