flink版本: flink-1.11.2
代碼位置: org.apache.flink.runtime.util.EnvironmentInformation
調(diào)用位置:? ?taskmanager啟動類: ?
org.apache.flink.runtime.taskexecutor.TaskManagerRunner文章來源:http://www.zghlxwxcb.cn/news/detail-683383.html
long maxOpenFileHandles = EnvironmentInformation.getOpenFileHandlesLimit();
注意,該方法主要調(diào)用了com.sun.management.UnixOperatingSystemMXBean接口下的getMaxFileDescriptorCount方法,所以一定要在Sun/Oracle的JDK下才能使用。另外只能在基于Unix內(nèi)核的操作系統(tǒng)中生效,其他系統(tǒng)下默認(rèn)返回-1.文章來源地址http://www.zghlxwxcb.cn/news/detail-683383.html
/**
* 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 Windows
return -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;
}
}
到了這里,關(guān)于flink源碼分析-獲取最大可以打開的文件句柄的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!