1).在打印日志时,咱们能够使用下面的代码:html
logger.debug("Entry Number :"+ i + " is "+String.valueOf(entry[i]));spring
这样作的效率比较低。由于他会遭受到【变量i】和【entry】转换成一个字符串,而且再加上字符串的拼接。这些时间无论你打印不打印这些日志都会消耗。app
即有可能你讲DEBUG的模式打印的日志的功能关闭了,可是上面那就话仍是会消耗时间。框架
2).可是若是变成下面的代码,就不会消耗时间了:ide
if(logger.isDebugEnabled()) { logger.debug("Entry number: " + i + " is " + String.valueOf(entry[i])); }
若是debug模式关闭,就不会消耗时间,若是debug模式是开放的,就会消耗时间。从而提升了效率性能
3).使用Logback中的字符串的占位符:spa
在logback中占位符是一对花括号:【{}】.debug
对于:日志
Object entry = new SomeObject(); logger.debug("The entry is {}.", entry);
若是日志须要的打印的话,就会将{}变成对应的变量的值。若是不须要打印的话,他也不会消耗时间。如同加上了htm
if(logger.isDebugEnabled()) {
这句话。提升了效率。
4)固然也可有多个变量的值:
logger.debug("The new entry is {}. It replaces {}.", entry, oldEntry);
Object[] paramArray = {newVal, below, above}; logger.debug("Value {} was inserted between {} and {}.", paramArray);
5)因此,在打印日志时:为了提升效率:有两种方式:
①加上logger.isDebugEnabled()或者logger.isInfoEnable()等等
②使用占位符。
----------------------------------------------------------------------------------------------------
下面是一个示例:打开debug
Bean复制的几种框架性能比较(Apache BeanUtils、PropertyUtils,Spring BeanUtils,Cglib BeanCopier)
cglib是最快的
若是是mapping映射使用: orika
另外还能够使用springside4(各类优秀框架集成)