Created
August 22, 2017 06:10
-
-
Save hengyunabc/744e1dc3cacd26e616195343de825787 to your computer and use it in GitHub Desktop.
java get fd count. openFileDescriptorCount / maxFileDescriptorCount
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>sun.jdk</groupId> | |
<artifactId>rt.jar</artifactId> | |
<version>1.8</version> | |
<scope>system</scope> | |
<systemPath>${java.home}/lib/rt.jar</systemPath> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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