나는 기사를 사용했다. http://www.devinline.com/2016/05/java-instrumentation-fundamental-part-1.html?m=1개체의 크기에 대한 계측의 사용
나는 쿼리 결과의 크기를 알아야한다.
그러나 호출
long sizeOfObject = InstrumentationAgent.findSizeOfObject(myvar);
의는
나는 클래스의 주요 방법이 있습니까?에이전트가 initted하지 않는 오류를 반환합니다.
Exception
당신이 옳은 구문에 대한 추천을 줄 수 발생과
계 : 에이전트 코드 :
package org.h2.command;
import java.lang.instrument.Instrumentation;
import java.lang.instrument.UnmodifiableClassException;
public class InstrumentationAgent {
/*
* System classloader after loading the Agent Class, invokes the premain
* (premain is roughly equal to main method for normal Java classes)
*/
private static volatile Instrumentation instrumentation;
public static void premain(String agentArgs, Instrumentation instObj) {
// instObj is handle passed by JVM
instrumentation = instObj;
}
public static void agentmain(String agentArgs, Instrumentation instObj)
throws ClassNotFoundException, UnmodifiableClassException {
}
public static long findSizeOfObject(Object obj) {
// use instrumentation to find size of object obj
if (instrumentation == null) {
throw new IllegalStateException("Agent not initted");
} else {
return instrumentation.getObjectSize(obj);
}
}
}
내 호출은 :
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.instrument.Instrumentation;
import org.h2.command.InstrumentationAgent;
import static java.lang.System.out;
public class CacheOptimize {
public long Size;
public static void main(String[] args) throws Exception {
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:file:D:/server/h2/exp1.h2.db", "sa", "sa");
Statement stat = conn.createStatement();
ResultSet rs;
rs = stat.executeQuery("select * from TAbles");
Size = InstrumentationAgent.findSizeOfObject(rs);
}
stat.close();
conn.close();
}
'MANIFEST.MF'및 에이전트 코드 표시 – vsminkov
nessasary 코드 추가 –
아무도 도와 줄 수 있습니까? –