flink版本: flink-1.11.2
代码位置: org.apache.flink.runtime.util.EnvironmentInformation
调用位置: taskmanager启动类:
org.apache.flink.runtime.taskexecutor.TaskManagerRunner
long maxOpenFileHandles = EnvironmentInformation.getOpenFileHandlesLimit();
注意,该方法主要调用了com.sun.management.UnixOperatingSystemMXBean接口下的getMaxFileDescriptorCount方法,所以一定要在Sun/Oracle的JDK下才能使用。另外只能在基于Unix内核的操作系统中生效,其他系统下默认返回-1.
/*** Tries to retrieve the maximum number of open file handles. This method will only work on* UNIX-based operating systems with Sun/Oracle Java versions.** <p>If the number of max open file handles cannot be determined, this method returns {@code -1}.</p>** @return The limit of open file handles, or {@code -1}, if the limit could not be determined.*/public static long getOpenFileHandlesLimit() {if(OperatingSystem.isWindows()) { // getMaxFileDescriptorCount method is not available on Windowsreturn -1L;}Class<?> sunBeanClass;try {sunBeanClass = Class.forName("com.sun.management.UnixOperatingSystemMXBean");} catch(ClassNotFoundException e) {return -1L;}try {Method fhLimitMethod = sunBeanClass.getMethod("getMaxFileDescriptorCount");Object result = fhLimitMethod.invoke(ManagementFactory.getOperatingSystemMXBean());return (Long) result;} catch(Throwable t) {LOG.warn("Unexpected error when accessing file handle limit", t);return -1L;}}