`
id.alex
  • 浏览: 22842 次
社区版块
存档分类
最新评论

dev tips

    博客分类:
  • Java
阅读更多
换行符:
String lineSeparator = (String) java.security.AccessController.doPrivileged(
               new sun.security.action.GetPropertyAction("line.separator"));


System.getProperty("line.separator")


网卡地址:
public static List<String> getAllMacAddresses()  
{  
    List<String> addresses = new ArrayList<String>();  
  
    StringBuffer sb = new StringBuffer();  
    try  
    {  
        Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();  
        while(networkInterfaces.hasMoreElements())  
        {  
            NetworkInterface netInterface = networkInterfaces.nextElement();  
            byte[] mac = netInterface.getHardwareAddress();  
            if(mac != null)  
                sb.delete(0, sb.length());  
            for(byte b : mac)  
            {  
                String hexString = Integer.toHexString(b & 0xFF);  
                sb.append((hexString.length() == 1) ? "0" + hexString : hexString);  
            }  
            addresses.add(sb.toString());  
        }  
    }  
    catch(SocketException e)  
    {  
        e.printStackTrace();  
    }  
  
    return addresses;  
}  


RandomAccessFile 中的 readLong 方法 慢
读取100W次要17秒, 自己读8byte,转成long 只要5秒.


log4j 常用的 ConversionPattern
总是要找以前的项目,留这找着方便.
引用

log4j.rootLogger=WARN,C,I,W,E

#Custom logger
#log4j.logger.Custom=INFO,Custom
#log4j.additivity.Custom=false

#Console appender
log4j.appender.C=org.apache.log4j.ConsoleAppender
log4j.appender.C.layout=org.apache.log4j.PatternLayout
log4j.appender.C.layout.ConversionPattern=[%-5p]-%d: %m (%F:%L)%n

#Info appender
log4j.appender.I=org.apache.log4j.DailyRollingFileAppender
log4j.appender.I.Append=true
log4j.appender.I.File=D://info.log
log4j.appender.I.layout=org.apache.log4j.PatternLayout
log4j.appender.I.layout.ConversionPattern=[%-5p]-%d: %m (%F:%L)%n
log4j.appender.I.filter.F=org.apache.log4j.varia.LevelRangeFilter
log4j.appender.I.filter.F.LevelMin=INFO
log4j.appender.I.filter.F.LevelMax=INFO

#Warn appender
log4j.appender.W=org.apache.log4j.DailyRollingFileAppender
log4j.appender.W.Append=true
log4j.appender.W.File=D://warn.log
log4j.appender.W.layout=org.apache.log4j.PatternLayout
log4j.appender.W.layout.ConversionPattern=[%-5p]-%d: %m (%F:%L)%n
log4j.appender.W.filter.F=org.apache.log4j.varia.LevelRangeFilter
log4j.appender.W.filter.F.LevelMin=WARN
log4j.appender.W.filter.F.LevelMax=WARN

#Error appender
log4j.appender.E=org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.Append=true
log4j.appender.E.File=D://error.log
log4j.appender.E.layout=org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern=[%-5p]-%d: %m (%F:%L)%n
log4j.appender.E.filter.F=org.apache.log4j.varia.LevelRangeFilter
log4j.appender.E.filter.F.LevelMin=ERROR
log4j.appender.E.filter.F.LevelMax=ERROR

#Custom logger appender
#log4j.appender.Custom=org.apache.log4j.DailyRollingFileAppender
#log4j.appender.Custom.Append=true
#log4j.appender.Custom.File=D://custom.log
#log4j.appender.Custom.layout=org.apache.log4j.PatternLayout
#log4j.appender.Custom.layout.ConversionPattern=[%-5p]-%d: %m (%F:%L)%n
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics