Skip to content

Instantly share code, notes, and snippets.

@hengyunabc
Created August 22, 2017 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hengyunabc/744e1dc3cacd26e616195343de825787 to your computer and use it in GitHub Desktop.
Save hengyunabc/744e1dc3cacd26e616195343de825787 to your computer and use it in GitHub Desktop.
java get fd count. openFileDescriptorCount / maxFileDescriptorCount
<dependency>
<groupId>sun.jdk</groupId>
<artifactId>rt.jar</artifactId>
<version>1.8</version>
<scope>system</scope>
<systemPath>${java.home}/lib/rt.jar</systemPath>
</dependency>
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import com.sun.management.UnixOperatingSystemMXBean;
public class Test {
public static void main(String[] args) {
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
if (operatingSystemMXBean instanceof UnixOperatingSystemMXBean) {
UnixOperatingSystemMXBean unixOperatingSystemMXBean = (UnixOperatingSystemMXBean) operatingSystemMXBean;
System.out.println("maxFileDescriptorCount: " + unixOperatingSystemMXBean.getMaxFileDescriptorCount());
System.out.println("openFileDescriptorCount: " + unixOperatingSystemMXBean.getOpenFileDescriptorCount());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment