Spring计时器StopWatch使用】的更多相关文章

我们可以利用已有的工具类中的秒表,常见的秒表工具类有org.springframework.util.StopWatch.org.apache.commons.lang.time.StopWatch以及谷歌提供的guava中的秒表. 下面用Spring的StopWatch演示下耗时统计及打印的功能: public static void main(String[] args) { StopWatch sw = new StopWatch("test"); try { //启动任务一 s…
计时器 StopWatch stwatch = new StopWatch(getClass().getSimpleName()); try{ stwatch.start(joinPoint.getSignature().getName()); //logic }finally{ stwatch.stop(); System.out.println(stwatch.prettyPrint()); } 参考文献: [1]http://www.concretepage.com/spring/stop…
简单总结一句,Spring提供的计时器StopWatch对于秒.毫秒为单位方便计时的程序,尤其是单线程.顺序执行程序的时间特性的统计输出支持比较好.也就是说假如我们手里面有几个在顺序上前后执行的几个任务,而且我们比较关心几个任务分别执行的时间占用状况,希望能够形成一个不太复杂的日志输出,StopWatch提供了这样的功能.而且Spring的StopWatch基本上也就是仅仅为了这样的功能而实现. 实际中用到的代码: public void run() { LOGGER.info("["…
import java.util.concurrent.TimeUnit; import org.junit.Test; import com.google.common.base.Stopwatch; public class GuavaTest { @Test public void testStopwatch() throws InterruptedException { // 创建自动start的计时器 Stopwatch watch = Stopwatch.createStarted(…
spring 计时器 可以这样: http://blog.csdn.net/u010648555/article/details/52162840 也可以使用annotation <!-- 设置定时任务 --> <task:annotation-driven/> @Service @Lazy(value=false) public class TaskWeixin { // @Scheduled(cron = "*/5 * * * * ?") // 每5秒处理一…
Spring 计时器 @Scheduled cron 含义 学习:http://blog.csdn.net/prisonbreak_/article/details/49180307 http://biaoming.iteye.com/blog/39532 一个cron表达式有至少6个(也可能7个)有空格分隔的时间元素. 按顺序依次为 秒(0~59) 分钟(0~59) 小时(0~23) 天(月)(0~31,但是你需要考虑你月的天数) 月(0~11) 天(星期)(1~7 1=SUN 或 SUN,M…
下面提供三种计时器的写法供大家参考,大家可以自行选择自己钟爱的使用. 写法一(Spring 包提供的计时器): import java.text.NumberFormat; import java.util.LinkedList; import java.util.List; /** * Simple stop watch, allowing for timing of a number of tasks, * exposing total running time and running ti…
1.使用 Stopwatch 类 (System.Diagnostics.Stopwatch)Stopwatch 实例可以测量一个时间间隔的运行时间,也可以测量多个时间间隔的总运行时间.在典型的 Stopwatch 方案中,先调用 Start 方法,然后调用 Stop 方法,最后使用 Elapsed 属性检查运行时间.Stopwatch 实例或者在运行,或者已停止:使用 IsRunning 可以确定 Stopwatch 的当前状态.使用 Start 可以开始测量运行时间:使用 Stop 可以停止…
背景 有时我们在做开发的时候需要记录每个任务执行时间,或者记录一段代码执行时间,最简单的方法就是打印当前时间与执行完时间的差值,然后这样如果执行大量测试的话就很麻烦,并且不直观,如果想对执行的时间做进一步控制,则需要在程序中很多地方修改,目前spring-framework提供了一个StopWatch类可以做类似任务执行时间控制,也就是封装了一个对开始时间,结束时间记录操作的Java类,小例一则如下   实例 package com.example.stopwatch; import org.s…
相关阅读 [小家java]java5新特性(简述十大新特性) 重要一跃 [小家java]java6新特性(简述十大新特性) 鸡肋升级 [小家java]java7新特性(简述八大新特性) 不温不火 [小家java]java8新特性(简述十大新特性) 饱受赞誉 [小家java]java9新特性(简述十大新特性) 褒贬不一 [小家java]java10新特性(简述十大新特性) 小步迭代 [小家java]java11新特性(简述八大新特性) 首个重磅LTS版本 前言 编码过程中我们经常会希望得到一段代码…