Java - getOpenFileDescriptorCount for Windows

How to get the number of open file descriptors in Windows?

Unix has the following:

UnixOperatingSystemMXBean.getOpenFileDescriptorCount()

But there seems to be no equivalent for windows?

+4
source share
1 answer

This will be a comment, but a little long.

Conflicting answers as to why there might be a lack of equivalence here on ServerFault: the maximum open file size for Windows Server 2008 R2 . TL; DR: Windows is limited only by available hardware, and Windows is limited to 32 or 64 bit implementation ( MS Technet Blog Post - Clicking Windows Restrictions: Handles ). Of course, this is old information.

! JavaDocs com.sun.management , , , Windows UnixOperatingSystemMXBean OperatingSystemMXBean. UnixOperatingSystemMXBean getMaxFileDescriptorCount() getOpenFileDescriptorCount(), , Windows .

Edit:

, , . Descriptors.java

import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.reflect.Method;

class Descriptors {
    public static void main(String [ ] args) {
        System.out.println(osMxBean.getClass().getName());
        OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();
        try {
            Method getMaxFileDescriptorCountField = osMxBean.getClass().getDeclaredMethod("getMaxFileDescriptorCount");
            Method getOpenFileDescriptorCountField = osMxBean.getClass().getDeclaredMethod("getOpenFileDescriptorCount");
            getMaxFileDescriptorCountField.setAccessible(true);
            getOpenFileDescriptorCountField.setAccessible(true);
            System.out.println(getOpenFileDescriptorCountField.invoke(osMxBean) + "/" + getMaxFileDescriptorCountField.invoke(osMxBean));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Linux:

com.sun.management.UnixOperatingSystem
11/2048

Windows:

sun.management.OperatingSystemImpl
java.lang.NoSuchMethodException: 
sun.management.OperatingSystemImpl.getMaxFileDescriptorCount()
at java.lang.Class.getDeclaredMethod(Unknown Source)
at Descriptors.main(Descriptors.java:10)
0

Source: https://habr.com/ru/post/1681987/


All Articles