log4J不妥当的写法
//log4j不妥当的写法
public class Xml2DataParserImpl {
private final Log log = LogFactory.getLog(Xml2DataParserImpl.class);
}
妥当的写法
public class Xml2DataParserImpl {
private static final Log log = LogFactory.getLog(Xml2DataParserImpl.class);
}
实际上, 如果class被实例化的次数比较小的时候, 这个对性能影响也不大。 一个小小的命令可以检查:
find . |grep -e "\.java$" |xargs grep "LogFactory.getLog" |grep -v static (commons log4j)或者 find . |grep -e "\.java$" |xargs grep "LoggerFactory.getLogger" |grep -v static (slf4j)
--摘自工作中线上性能方面