Announcement Announcement Module
No announcement yet.
which is better way to implement performance advice ? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • which is better way to implement performance advice ?


    say i have a method that want to profile it time of execute and display on the webpage with result.

    public interface Xservice
       public Result execute();
    so I add a before and after advice like this

    public class perfomanceAdvice
       public static int timeExecuted;
       public void getStart()
         // get start time
       public void getEnd()
         //get end time by substract the start time
    since i need to store the result, i maybe introduce a instance variable, my question is :

    1) since the advice is a singleton, it will use on all the service, say my service is not singleton and use by multiple thread, will it produce inaccurate result, since make it synchronized seem like doesn't make sense. (ok, maybe approximate result is enough, but i wondering it this make sense )

    2) is that any other solution for this ? my gaol is to get the "timeExecuted" for rendered in web page, should we access the directly (is that possible ?) or this solution is enough.

    i have try with difference thread (10 thread with every thread get the new object prototype) instead of sharing same instance (singleton) and get the difference results.

    the result produce by singleton case, result almost all same but the prototype case produce result that is quite differences. (which i think more reflect the real scenario)

    my code is simply call a Thread.sleep(x second) to tes the behaviour.

    what u think ?

    happy hacking !

  • #2
    Simply use an around advice, start timing before calling the proceed method and end timing before returning the value.

    And for you convenience spring already has one for you the PerformanceMonitoringInterceptor which does just that. You also might want to look at the AbstractMonitoringInterceptor
    class tree, because there are multiple implementations you can use.

    Edit: just saw that you want something like this for displaying something on the web.

    Simply implement a HandlerInterceptor (assuming you are using Spring MVC) and it is quite easy to implement.
    Last edited by Marten Deinum; Jun 3rd, 2008, 04:57 AM.