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 ...
随机推荐
- npm 安装express npm ERR! code UNABLE_TO_VERIFY_LEAF_SIGNATURE
npm安装总是报错 报错信息: 解决方案: 在命令行输入: npm config set strict-ssl false 设置之后即可安装软件:
- 如何锁定Android系统CPU的频率
接触到了Android系统的Performance测试,所以有锁定CPU的需求: 由于要首先读取到此系统所支持的CPU频率,之后再所支持的频率中选取你想要的频率,之后进行锁定. 这个过程,手动也是可以 ...
- meta-data
<meta-data android:name="string" android:resource="resource specification" ...
- CentOS-文件操作
centos彻底删除文件夹.文件命令(centos 新建.删除.移动.复制等命令: 1.新建文件夹 mkdir 文件名 新建一个名为test的文件夹在home下 view source1 mkdir ...
- idea Live Template 快速使用
善用LiveTemplates,好用到没朋友,我凑揍 , 尊重原创,原文链接: https://blog.csdn.net/u012721933/article/details/52461103#co ...
- NHibernate N+1问题实例分析和优化
1.问题的缘起 考察下面的类结构定义 public class Category { string _id; Category _parent; IList<Category> _chil ...
- ogre的初始化与启动以及显示对象设置
ogre的使用方法1---自动设置 1.ogre初始化:首先实例化一个Root对象 Root * root = new Root(); Root * root = new Root("plu ...
- TensorFlow——热身运动:简单的线性回归
过程: 先用numpy建立100个数据点,再用梯度下滑工具来拟合,得到完美的回归线. # _*_coding:utf-8_*_ import tensorflow as tf import numpy ...
- HAZU校赛 Problem K: Deadline
Problem K: Deadline Time Limit: 2 Sec Memory Limit: 1280 MB Submit: 1106 Solved: 117 [Submit][Status ...
- Welcome-to-Swift-24高级运算符(Advanced Operators)
除了基本操作符中所讲的运算符,Swift还有许多复杂的高级运算符,包括了C语和Objective-C中的位运算符和移位运算. 不同于C语言中的数值计算,Swift的数值计算默认是不可溢出的.溢出行为会 ...