Re: Formatting a date

Keats Kirsch <[email protected]> Thu, 30 Mar 2006 10:05:41 -0500
Newsgroups gmane.comp.java.webmacro.user
Message-ID <[email protected]>
Good catch Endre!  Glad I didn't go down that path yet.  Perhaps we=20
should look for an alternative date formatting system.  I found=20
something called Joda Time on SourceForge (http://www.joda.org/) that=20
looks like it might fit the bill.  From their FAQ:

"The most common multi-threading mistake made by Java programmers is in=20
the use of SimpleDateFormat. Calling its format method on a shared=20
instance by concurrent threads can produce bizarre results. All of=20
Joda-Time's formatting classes are thread-safe and immutable."

They also claim it is faster than SimpleDateFormat.

Keats

Endre St=F8lsvik wrote:

>...
>
>| Is (Simple)DateFormat itself completely thread-safe, by contract?
>
>Forgot to point out that you obvioulsy may just do both the map-lookup=20
>_and_ the formatting within the one synch-block (but then you can forget=
=20
>the benefit of ConcurrentHashMap) - or you could have a pool of each=20
>format - say 10 instances - and actually do "connection pooling" logic.
>  But at that point, I do hope that more than me thinks that having "one=
=20
>more cached resource" (with the synch and potential contention hit (now=20
>both for the synch and the formatting-time), and "memory bloat") for tha=
t=20
>amazingly little benefit (e.g. 1 ms for 40 formattings) isn't worth the=20
>hassle?
>
>Add a method to dateTool that actually gives you a DateFormat back, and=20
>javadoc both methods where the users are told to use the=20
>DateFormat-returning one if they're about to format multiple dates in on=
e=20
>rendering.
>
>Regards,
>Endre.
> =20
>




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting langua=
ge
that extends applications into web and mobile media. Attend the live webc=
ast
and join the prime developer group breaking into this new coding territor=
y!
http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D110944&bid=3D241720&dat=3D=
121642