1 Overview
You need to record the execution time of each task, or record a period of code execution, simply by printing the difference between the current time and the execution time, and if performing a large number of tests is cumbersome and not intuitive. If you want to control the execution time further, you need to modify it in many parts of the program. Spring-framework provides a stopwatch class that can do similar task execution time control.
stopwatch SW = new stopwatch ();
Sw.start ();
Business Operation
Sw.stop ();
Logger.info ("Time consuming:" + sw.gettotaltimemillis ());
2 match interceptors use spring stopwatch in the filter to count the execution times of each request. Add the following code to the Dofilter of filter:
Stopwatch stopwatch = new Stopwatch (Url+system.currenttimemillis ());
Stopwatch.start ();
Dofilter (ARG0,ARG1);
Opwatch.stop ();
Loginfo (Stopwatch.gettotaltimemillis () + "---" +request.getrequesturi () + "Execution Time");
As you can see from the source code constructs, stopwatch constructs the object according to the ID, ensuring that the unique construction ID distinguishes between different requests.
Public stopwatch () {
keeptasklist = true;
TaskList = new LinkedList ();
id = "";
}
Public stopwatch (String ID) {
keeptasklist = true;
TaskList = new LinkedList ();
This.id = ID;
}
Original posted Address: http://blog.csdn.net/linfssay/article/details/7680323
http://blog.csdn.net/u012186154/article/details/54923210