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 ...
随机推荐
- The 2018 ACM-ICPC China JiangSu Provincial Programming Contest I. T-shirt
JSZKC is going to spend his vacation! His vacation has N days. Each day, he can choose a T-shirt to ...
- MIP启发式算法:Variable fixing heuristic
*本文主要记录及分享学习到的知识,算不上原创 *参考文章见链接. 本文简单介绍一下Variable fixing heuristic,这个算法同样以local search为核心框架,它的特点在于定义 ...
- CDH4 journalnode方式手工安装手册之一
一. 环境部署概况 cdh-master 172.168.10.251 cdh-node1 172.168.10.251 cdh-no ...
- python - work5 - 类与对象
# -*- coding:utf-8 -*- '''@project: jiaxy@author: Jimmy@file: work_20181119.py@ide: PyCharm Communit ...
- 【LeetCode】Balanced Binary Tree(平衡二叉树)
这道题是LeetCode里的第110道题. 题目要求: 给定一个二叉树,判断它是否是高度平衡的二叉树. 本题中,一棵高度平衡二叉树定义为: 一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过1. ...
- TensorFlow笔记——
主要依赖包 protocal buffer 处理结构化数据的工具:序列化(结构化数据->数据流) + 还原(数据流->结构化数据) protocol buffer与XML和JSON的区别: ...
- 【mysql优化 3】嵌套循环连接算法
原文地址:Nested-Loop Join Algorithms mysql在表之间执行连接操作,包括了使用循环嵌套算法或者其他在此基础上的变形. 循环嵌套连接算法: 一个简单的嵌套循环连接(NLJ: ...
- C# 条件与&&与条件或||的使用总结
CSDN说明: 条件“或”运算符 (||) 执行 bool 操作数的逻辑“或”运算,但仅在必要时才计算第二个操作数. 件“与”运算符 (&&) 执行其 bool 操作数的逻辑“与”运算 ...
- 实现chrome多用户独立cookie
2018-02-08 10:58:57 在浏览器设置中添加一个用户并创建桌面快捷方式,属性中我们可以发现 "C:\Program Files (x86)\Google\Chrome\Appl ...
- 备忘 CSS字体中英文名称对照表
转载自:http://www.jb51.net/css/67658.html 在CSS文件中,我们常看到有些字体名称变成了乱码,这是由于编写者将中文字体的名字直接写成了中文,并且再上传或者拷贝复制的时 ...