を見ることができれば、私はあなたがあなたのクラスのためのインタフェースを必要とする私は、このソリューション
最初に提案し、いくつかの方法がJMXを介して実行されているどのように多くの時間を見てみたい素晴らしいことです。
public interface RPCServerInterface {
int countMethodInvocation(String method);
}
次に、各関数が呼び出した回数をクラスに格納します。
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
RPCServer rpcServer = new RPCServer();
ObjectName objectName = new ObjectName("org.foo.RPCServer.jmx:type=RPCServerInterface");
StandardMBean standardMBean = new StandardMBean(rpcServer,RPCServerInterface.class);
mBeanServer.registerMBean(standardMBean, objectName);
org.foo.RPCServer.jmxは任意であるパス:
public class RPCServer implements RPCServerInterface{
private int row;
private Map<String,Integer> countByMethod = new HashMap<String,Integer>();
// +1 to the number of time of execution of this method
private void sumMethodInvocation(String method) {
if (countByMethod.containsKey(method)) {
int n = countByMethod.get(method);
countByMethod.put(method, n+1);
} else {
countByMethod.put(method,1);
}
}
// how many time the method has been invoked
@Override
public int countMethodInvocation(String method){
return countByMethod.containsKey(method)?countByMethod.get(method):0;
}
public void setRow(int i) {
// register each time is executed
this.sumMethodInvocation("setRow");
this.row = i;
}
public int getRow() {
// register each time is executed
this.sumMethodInvocation("getRow");
return row;
}
}}
}
次に、あなたのビーンを登録する必要があります。
次に、jconsoleを実行し、実行中のプロセスを見つけます。
その後、コマンドcountMethodInvocationを実行することができますし、実行時間の数を取得することができます。このよう
:
このチュートリアルでは、役立つことができます:
what-is-jmx-mbean-jconsole-tutorial
こんにちは!これをありがとうございました。私のbeanを登録するためのコードはどこに置くのですか? – user1870400
アプリケーションのいくつかの場所で、おそらくメインの直後です。 – Troncador
私はあなたの質問に答えていると感じたら、私の答えをチェックしてください:p – Troncador