Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

SimpleDateFormat and Thread safety

user1980584Feb 28 2013 — edited Mar 1 2013
I have a question with regards to SimpleDateFormat and it's lack of thread safety.

I have a DateUtils class which does a series of date related operations, one among them being parsing wherein this static method takes in a string and parses it to a Date. I have a couple of SimpleDateFormats and this method spins thru' those and returns back a Date as soon as a matching format is found. The problem I'm encountering is that these SimpleDateFormats are being stored in an array that is static (since the method is static - as it is within an util class, had to declare this array as static as well). With this configuration, isn't it true that this poses a threat when multiple threads are running simultaneously? If so, should I use ThreadLocal to make it thread safe? Or, can I somehow remove the "static" declaration and make it work?

Thanks in advance.
This post has been answered by jtahlborn on Mar 1 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 29 2013
Added on Feb 28 2013
8 comments
1,094 views