Start another virtual machine with the first Java Virtual machine, and use the Java program of the first virtual machine to test the memory of the Java program running on another virtual machine, CPU resource usage.
Limitations and conditions for resolving problems:
1 "Two virtual machines run on the same windows_x86 machine.
2 only need to know the second virtual machine to run the program, the secondary VM memory, CPU usage.
3 The purpose is: to test different programs on the same virtual machine resource usage differences.
The key to solving the problem:
The first way to start a Java program that runs tests on another virtual machine.
Second, how to monitor the operation of another virtual machine and its associated processes with Java programs in the first virtual machine.
Solution:
First, the use of the functions in java.io (command tried no problem, the program please press the following prompts to complete)
Using the functions in java.io
Runtime.getruntime (). EXEC ("system command");
Here I give an example with command parameters
Runtime r=Runtime.getRuntime();
Process p=null;
String cmd[]={"命令","参数"};
try{
p=r.exec(cmd);
}
catch(Exception e){
System.out.println("error executing: "+cmd[0]);
}
Here are a few of the system commands to use:
Path/java file
Run Java program file with the second JVM (path for the second jre/bin/address)
tasklist > Log.txt
Writes the current system process to the Log.txt file in the format of Task Manager (), regarding tasklist usage details, such as querying a process ID to use the command >tasklist/? Make a query
Both of these steps are completed in the first virtual machine, simple!!!
Ii. general methods of using JNI
Here I give a set of solutions, the Internet has a lot of relevant code, to find their own;
This program can also be implemented, where I use the simple implementation of C # to do the monitoring, but this scheme obviously has its shortcomings; The test object's JNI interface will be triggered, of course, if the data is not required to be accurate, from a comparative perspective alone, As long as the operation does not itself not use JNI this scheme is still feasible.