简体   繁体   中英

StopWatch in javaSimon vs ? in javaMelody

i'm currently replacing javaSimon with javaMelody: we use the StopWatch from JavaSimon to monitor the time used to execute the core functions. This needs to be replaced by using JavaMelody. So when we enable the monitoring for core functions. JavaMelody can report the performance of the core functions.

any idea about the stopWatch in JavaMelody Please ?

If what you want to monitor is the execution of methods, you can do that using Spring or EJB/CDI or simple java interfaces . The results will be displayed in the statistics of the reports.

Or if what you want to monitor is just the execution of some pieces of codes, you can create methods and monitor them. For example:

Runnable runnable = new Runnable() {
   @Override
   public void run() {
      // your piece of code
   }
};
runnable = MonitoringProxy.createProxy(runnable, "name you want in the statistics");
runnable.run();

And to make the monitoring of pieces of code simpler, I have just added a new simple API in javamelody and so you could do now:

try (Stopwatch stopwatch = new Stopwatch("name you want in the statistics")) {
      // your piece of code
}

The results will also be displayed in the statistics of the reports. For that last one, you will need a snapshot build to be released in 1.77.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM