from javadoc on SimpleDateFormat:


Synchronization

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.

... so your concern is quite valid ... kind of. The time I could see a problem arising would be when you are *changing* the format. All methods that do not depend on instance-level variables would enjoy thread-safe-ness. My suspicion is that the format and parse methods would rely on the pattern, which seems to be a instance variable. So ... as long as you don't change the pattern you should still be fine ... I think.

Did I miss something else?

In other words: Assuming you use one pattern everywhere - and assuming you set that pattern in the static initializer for the class using the SimpleDateFormat (notice that I'm basically saying that pattern is never modified in more than a single thread at a time), everything should be ... just fine. Right? I can't see parse and format being non-threadsafe assuming pattern does not change.

Now, if you wanted to be able to actually *change* the format being used in the middle somewhere ... you would have a possible problem :-) Until you have a need to do that, you don't need to synchronize.

Kris Schneider wrote:

Apologies if I'm misinterpreting, but I think Antoni's concern is that the SimpleDateFormat's parse and format methods are not thread-safe. The creation of the converters and their registration can obviously be accomplished in a thread-safe manner, but if multiple threads call into parse and/or format at the same time, this will cause a problem. If that's not what Antoni was saying...it's still a problem ;-). Shouldn't you code a Converter's convert method with the same approach to thread-safety as an Action's execute/perform method? If your Converter maintains a SimpleDateFormat instance field that it uses to either format or parse, it's not thread safe.

--
Eddie Bush




--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@;jakarta.apache.org>

Reply via email to