Google Guava学习计划第一章Guava Utilities—StopWatch和ServerLoader
来源:互联网 发布:java模拟微信浏览器 编辑:程序博客网 时间:2024/05/16 00:29
写文章之前,先给大家分享今天刚买的一个玩具,科大讯飞的阿尔法蛋,哈哈,真的很不错。
今天介绍的是StopWatch和ServerLoader的简单用法。
StopWatch: 在程序中我们总会需要log某个程序的执行时间,可以采用stopwatch,它底层代码对时间进行一系列转化,配合log4j2很好用。
ServerLoader:从1.6引入,在java1.9 会推荐模块化编程,会特别有用。不同模块调用接口,可以通过ServerLoader来加载
直接撸代码
ackage Utilities;import com.google.common.base.Stopwatch;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import java.time.Duration;import java.util.concurrent.TimeUnit;/** * ${DESCRIPTION} * * @author mengxp * @version 1.0 * @create 2017-12-14 20:43 **/public class StopWatcherTest { public static final Logger LOGGER = LogManager.getLogger(StopWatcherTest.class); public static void main(String[] args) throws Exception { Stopwatch stopwatch=Stopwatch.createStarted(); TimeUnit.MILLISECONDS.sleep(5); Duration elapsed = stopwatch.stop().elapsed(); //{} 这个符号在log中类似于占位符 和printf很相似 LOGGER.info("spend [{}],[{}]",elapsed.toString(),"mengxiaopeng"); }}
阅读全文
0 0
- Google Guava学习计划第一章Guava Utilities—StopWatch和ServerLoader
- Google Guava学习计划第一章Guava Utilities—Joiner and Splitter
- Google Guava学习计划第一章Guava Utilities—Preconditions_ComparisonChain_Strings_CharMatcher
- Google Guava学习计划第一章Guava Utilities—Function_Predicate_Maps_Sets
- Google Guava学习计划第三章Guava Utilities—I/O操作
- Google guava
- Google Guava
- google guava
- google guava
- Google Guava
- guava的停表使用, Stopwatch
- Guava
- Guava
- Guava
- GUAVA
- guava
- guava
- Guava
- 【数学】Frobenius介值定理:非负矩阵最大特征值的上下界
- ubuntu16.04工具记录
- 数据结构期末总结
- CentOS7 VIM常用命令
- spark实时查看来自各个省份的ip访问
- Google Guava学习计划第一章Guava Utilities—StopWatch和ServerLoader
- Hdoj 1003 Max Sum
- ReentrantLock底层实现 小结
- 04.openssl-创建 Root CA证书
- 内存知识梳理 4. 内存管理
- Python SyntaxError: Non-ASCII character '\xff' in file
- ubuntu系统常见问题
- Bootstrap(二十五)
- BZOJ 1070 修车-神奇网络流