使用FastDateFormat来代替JDK自带的DateFormat

SimpleDateFormat来做Date到String的类型转换,建议我使用Apache commons-lang中的FastDateFormat。因为JDK里自带的SimpleDateFormat存在线程不安全问题。

 
改进方法有:
1.使用局部变量。有些时候希望SimpleDateFormat作为静态变量存在时候,这种情况不适用。
2.使用ThreadLocal。好是好,但是比较麻烦。更多请参考ThreadLocal的理解与在Spring中的应用
3.使用Apache commons-lang中的FastDateFormat。又快又线程安全,最佳选择。

Leave a Comment.