spring计时工具类stopwatch用法
public class Test {
public static void main(String[] args) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
try {
Thread.currentThread().sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
stopWatch.stop();
System.out.println(stopWatch.prettyPrint());
}
}
或
打印每个任务执行时间,以及占总时间百分比 package com.common.suanfa; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import org.springframework.util.StopWatch; public class Singleton {
public static void main(String[] args) throws ClassNotFoundException,
InstantiationException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException {
Class name = Class.forName("com.common.suanfa.Singleton");
Method[] m = name.getDeclaredMethods();
StopWatch stopWatch = new StopWatch("test");
Object o = name.newInstance();
for (Method mm : m) {
if (mm.getName() != "main") {
stopWatch.start(mm.getName());
mm.invoke(o);
stopWatch.stop();
}
}
System.out.println(stopWatch.prettyPrint());
} private static void method1() {
int i = Integer.MAX_VALUE;
long sum = 0l;
while (i-- > ) {
sum += i;
}
System.out.println(sum);
} private static void method2() {
int i = Integer.MAX_VALUE;
long sum = 0l;
while ((i -= ) > ) {
sum += i;
}
System.out.println(sum);
}
}
output: StopWatch 'test': running time (millis) =
-----------------------------------------
ms % Task name
-----------------------------------------
% method1
% method2
spring计时工具类stopwatch用法的更多相关文章
- Spring的Assert工具类的用法
简介 今天在看spring mvc源码时看到下面代码,感觉蛮有意思的,在这里记录下 Assert断言工具类,通常用于数据合法性检查,在JAVA编程中,通常会编写如下代码: if (name == nu ...
- Spring工具类ToStringBuilder用法简介
比如说我们需要打印某个方法的User参数对象 package test; /** * * @author zhengtian * @time 2012-6-28 */ public class Use ...
- 2015第30周三Spring常用工具类
文件资源操作 文件资源的操作是应用程序中常见的功能,如当上传一个文件后将其保存在特定目录下,从指定地址加载一个配置文件等等.我们一般使用 JDK 的 I/O 处理类完成这些操作,但对于一般的应用程序来 ...
- Spring常用工具类
Spring框架下自带了丰富的工具类,在我们开发时可以简化很多工作: 1.Resource访问文件资源: 具体有: ResourceUtils.getFile(url); FileSystemReso ...
- Spring boot 工具类静态属性注入及多环境配置
由于需要访问MongoDB,但是本地开发环境不能直接连接MongoDB,需要通过SecureCRT使用127.0.0.2本地IP代理.但是程序部署到线上生产环境后,是可以直接访问MongoDB的,因此 ...
- spring注解工具类AnnotatedElementUtils和AnnotationUtils
一.前言 spring为开发人员提供了两个搜索注解的工具类,分别是AnnotatedElementUtils和AnnotationUtils.在使用的时候,总是傻傻分不清,什么情况下使用哪一个.于是我 ...
- Spring web 工具类 WebApplicationContextUtils
概述 Spring web 的工具类 WebApplicationContextUtils 位于包 org.springframework.web.context.support 是访问一个Servl ...
- Spring的工具类StringUtils使用
我们经常会对字符串进行操作,spring已经实现了常用的处理功能.我们可以使用org.springframework.util.StringUtils 工具类帮我们处理字符串. 工具类整理如下: ...
- Spring 常用工具类
1) 请求工具类 org.springframework.web.bind.ServletRequestUtils //取请求参数的整数值: public static Integer getIntP ...
随机推荐
- spring+struts2+hibernate框架依赖pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- debian7不能apt安装emacs24
维护者在主页上 http://emacs.naquadah.org/ 提到: These packages are not maintained anymore I don't use these p ...
- HDU 5528 Count a * b 欧拉函数
题意: 定义函数\(f(n)\)为\(i \cdot j \not\equiv 0 \; (mod \; n)\)的数对\((i,j)\)的个数\((0 \leq i,j \leq n)\) \(g( ...
- [转] immutability-helper 插件的基本使用(附源码)
概念 先理解一下 Immutable 的概念,Immutable数据就是一旦创建,就不能更改的数据.每当对Immutable对象进行修改的时候,就会返回一个新的Immutable对象,以此来保证数据的 ...
- Selenium WebDriver- actionchians模拟鼠标悬停操作
#encoding=utf-8 import unittest import time from selenium import webdriver from selenium.webdriver i ...
- 【185天】黑马程序员27天视频学习笔记【Day14-下】
叨逼叨两句 不容易,白天被叫去帮忙,不得已晚上来挑灯夜战,熬到2点,总算完成任务了. 我打算下周开始换一个更新时间,每次把deadline设置为晚上12点,都会接近或者超过这个时间,之后改成中午12点 ...
- [转]linux多命令的顺序执行
当我们需要一次执行多个命令的时候,命令之间需要用连接符连接,不同的连接符有不同的效果. (1) ; 分号,没有任何逻辑关系的连接符.当多个命令用分号连接时,各命令之间的执行成功与否彼此没有任何影响,都 ...
- JDBC 学习笔记(五)—— Statement
JDBC 使用 Statement 作为 SQL 语句的执行器. Statement 通过 Connection.createStatement() 方法创建,一共支持以下6种方式执行 SQL 语句: ...
- BZOJ3507 [Cqoi2014]通配符匹配 【哈希 + 贪心】
题目 几乎所有操作系统的命令行界面(CLI)中都支持文件名的通配符匹配以方便用户.最常见的通配符有两个,一个 是星号(""'),可以匹配0个及以上的任意字符:另一个是问号(&quo ...
- 轻量级神经网络平台tiny-dnn实践
tiny-dnn跑起来 github: https://github.com/tiny-dnn/tiny-dnn#build 先上github下载tin ...