Ahti Kitsik
Building tools with Python, Java, Go, JS. For enquiries email inbox@ahtik.com

writings biography

SimpleDateFormat is not thread-safe

07 Nov 2008 by @ahtik

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!