在日常Java语言开发时,有时候需要监控方法中代码块的运行时长,从而确定性能点在哪,以及针对性的如何优化。利用springframework框架的工具类StopWatch可以快速方便的查看到每段代码运行的时间,准确确定性能瓶颈所在。
示例代码
@Test
public void test01() {
StopWatch stopWatch = new StopWatch();
stopWatch.start("a");
ApplicationContext ctx = new ClassPathXmlApplicationContext("com/springframework/chapter34/applicationContext.xml");
UserManager userManager = ctx.getBean(UserManager.class);
stopWatch.stop();
stopW