JVM_Info クラスの機能は、JVM の最大ヒープ・サイズを検索することです。
package test;
import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;
import java.net.*;
/**
* JVM_Info クラスの機能は、JVM の最大ヒープ・サイズを検索することです。
* このクラスを使用すると、テスト・ログにメッセージが書き込まれ、JVM が動作している
* ホストのホスト名と JVM の最大ヒープ・サイズがメガバイト単位で付記されます。
*/
/**
* @作成者 IBM カスタム・コード・サンプル
*/
public class JVM_Info implements
com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
public JVM_Info() {
}
public String exec(ITestExecutionServices tes, String[] args) {
Runtime rt = Runtime.getRuntime();
long maxMB = rt.maxMemory()/(1024*1024); // maxMemory() size is in bytes
String hostName = "Unknown";
try {
hostName = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e1) {
tes.getTestLogManager().reportMessage("Can't get hostname");
return null;
}
tes.getTestLogManager().reportMessage("JVM maximum heap size for host "
+ hostName + " is " + maxMB + " MB");
return null;
}
}