1. 程式人生 > >[Java] find out number of files currently open

[Java] find out number of files currently open

現在遇到一個 linux 的 fd(開檔數量)過多造成的的系統問題。所以需要一個 java sample code 來 monitor current file.

Example Code below

import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import com.sun.management.UnixOperatingSystemMXBean;
public class OpenFileCount{
    public static
void main(String[] args){ OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); if(os instanceof UnixOperatingSystemMXBean){ System.out.println("Number of open fd: " + ((UnixOperatingSystemMXBean) os).getOpenFileDescriptorCount()); } }
}