Thursday, June 02, 2005

SimpleDateFormat is not Synchronized

วันนี้อ่านเจอประเด็นนี้ใน Tapestry mailing list
SimpleDateFormat is not thread safe. You will get weird behavior
under high concurrency. It cannot be static in the Global


ใน javadoc ก็ย้ำไว้ว่า
Date formats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.


คุ้นๆว่าเคยประกาศ SimpleDateFormat ให้เป็น public static เหมือนกัน
(หวังดี อยากลด resource)

ทางเลือก
เปลี่ยนไปใช้ thread-safe FastDateFormat ของ jakarta commons lang แทน

Related link from Roti

No comments: