@IgnoreJRERequirement // UnixOperatingSystemMXBean
    private static void getOpenFileDescriptorCount(PrintWriter writer) throws UnsupportedEncodingException {
        try {
            OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
            if (operatingSystemMXBean instanceof UnixOperatingSystemMXBean) {
                UnixOperatingSystemMXBean unixOperatingSystemMXBean = (UnixOperatingSystemMXBean) operatingSystemMXBean;
                writer.println("Open File Descriptor Count: " + unixOperatingSystemMXBean.getOpenFileDescriptorCount());
            } else {
                writer.println("Wrong bean: " + operatingSystemMXBean);
            }
        } catch(LinkageError e) {
            writer.println("Unable to get the total number of open file descriptors using OperatingSystemMXBean");
        }
    }
@ IgnoreJRERequirement private static void getOpenFileDescriptorCount ( PrintWriter writer ) throws UnsupportedEncodingException { try { OperatingSystemMXBean operatingSystemMXBean = ManagementFactory . getOperatingSystemMXBean ( ) ; if ( operatingSystemMXBean instanceof UnixOperatingSystemMXBean ) { UnixOperatingSystemMXBean unixOperatingSystemMXBean = ( UnixOperatingSystemMXBean ) operatingSystemMXBean ; writer . println ( "Open File Descriptor Count: " + unixOperatingSystemMXBean . getOpenFileDescriptorCount ( ) ) ; } else { writer . println ( "Wrong bean: " + operatingSystemMXBean ) ; } } catch ( LinkageError e ) { writer . println ( "Unable to get the total number of open file descriptors using OperatingSystemMXBean" ) ; } }
* Using OperatingSystemMXBean, we can obtain the total number of open file descriptors.