일부 정보가 들어있는 텍스트 파일을로드하고 해당 정보를 기반으로 여러 스레드를 실행하는 프로그램이 있습니다. 각 스레드는 하나의 프로세스입니다. 여기에 내 코드입니다 : 내가 runMultiClient
클래스에서 그 변수에 도달 할 수있는 방법이 있나요프로세스 CPU 사용량 얻기
OperatingSystemMXBean osBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
cpuLoad = osBean.getProcessCpuLoad();
: 내 Client.jar
파일 내부
public class runMultiClient {
public static void main(String[] args){
List<Process> PRlist = new ArrayList<Process>();
List<String[]> commandsList = new ArrayList<String[]>();
boolean running = true;
if (args.length == 2 && args[0].matches("-f")){
String dir = System.getProperty("user.dir");
String path = dir + "/" + args[1];
FileReader fr;
try {
fr = new FileReader(path);
BufferedReader bf = new BufferedReader(fr);
String line = "";
while ((line = bf.readLine()) != null){
String[] tk = line.split(" ");
String[] cmd = {"java", "-jar", "Client.jar", "-a", tk[0], "-p", tk[1],
"-u", tk[2], "-pw", tk[3], "-m", tk[4], "-s", tk[5]};
Process pr = new ProcessBuilder().inheritIO().command(cmd).start();
PRlist.add(pr);
commandsList.add(cmd);
System.out.println(tk[4] + " streaming process is established.");
}
}
catch (FileNotFoundException ex) {ex.printStackTrace();}
catch (IOException ex) {ex.printStackTrace();}
} else {
System.out.println("No stream file was specified.");
}
}}
, 그 클래스의 CPU 부하를 모니터링하는 변수가 ? 그렇지 않은 경우 실행중인 프로세스에서 OperatingSystemMXBean
을 사용하는 방법이 있습니까? 나는 pr.getClass()
을 시도했지만, 아무데도 없어. 도움이 될 것입니다.
당신이 완전한 클래스를 제공 할 수 있습니다를 어디에 cpuLoad 변수 위치 ? – developer
할 수는 있겠지만 어떻게 도와 줄 수 있습니까? –
'cpuLoad'는 다른 클래스의 공용 변수입니다. –