开发者

how to create a plugin for web application to calculate the each and every invoked method execution time

开发者 https://www.devze.com 2023-04-11 23:20 出处:网络
My application file (EAR) consists of combination of EJB and WAR. FrameWork is JSF and IDE is Netbeans 6.9.1 applition server is glassfich V2.x. I want to calculate the execution time fro each and eve

My application file (EAR) consists of combination of EJB and WAR. FrameWork is JSF and IDE is Netbeans 6.9.1 applition server is glassfich V2.x. I want to calculate the execution time fro each and every invoked method in my application. i have gone through so many blogs. most of them suggested to use AOP. but nobody tell me how to configure and how to use it in my application. could anybody tell me ragarding this. I have some code here and i made use of AOP and JAMon to calculate the method execution time. but i confused about how to configure this because for every method invocation this calss should be invoked for that what to do i dont know. could anybody give some suggestions on it.If you any additional details to answer this i will provide. Code is:

public开发者_开发百科 class PerformanceMonitorIncptr implements MethodInterceptor{

/** Creates a new instance of PerformanceMonitorIncptr */
public PerformanceMonitorIncptr() {
}
public Object invoke(MethodInvocation mi) throws Throwable {
    String mName = mi.getMethod().getDeclaringClass().getName() + "." + mi.
            getMethod().getName();
    Monitor mon = MonitorFactory.start(mName);
//    long l = System.currentTimeMillis();
    Object returnValue = null;
    try {
        returnValue = mi.proceed();
    } finally {
        mon.stop();
        System.out.println(mon);
    }
    System.out.println(mName);
//    System.out.println(l - System.currentTimeMillis());
    return returnValue;

 }
}


AOP is best suited here.

You need to configure @PointCut @Around each method you want to log the time of execution

Have a look at this tutorial .

Update

I hope 20 methods you are talking about /can be are Spring Service methods, and you don't need to alter them at all you just need to configure a @Aspect that will involve all the methods. read more


AOP is the solution.

But why would you write it yourself.

Use Javamelody -> EJB configuration documentation.

We use it with Spring, and it's great. There are also such solutions as AppDynamics, DynaTrace, NewRelic, JXInsight, CorrelSense, Nastel. As for me Javamelody is free, opensource and very easy to use.

0

精彩评论

暂无评论...
验证码 换一张
取 消