Ahti Kitsik
Building develper tools. Python, Java, JavaScript.

writings about @ahtik

SimpleDateFormat is not thread-safe

By Ahti Kitsik, 07 Nov 2008

How many of you use java.text.SimpleDateFormat as static field?

I have seen this to be pretty standard practice (and have done this myself too).

Be aware that SimpleDateFormat#format(..) is not thread-safe and thereby for most of the cases you should not use this as a static field in server, Eclipse RPC or any other multi-threaded environment.

SimpleDateFormat is internally using field "calendar" that is set with each #format(...) method call so that pretty much breaks the thread-safety.

@ahtik is on twitter!