[Opensource] SimpleDateFormat

Michael Rimov rimovm at centercomp.com
Wed Mar 12 22:06:29 PST 2003


At 11:53 AM 3/12/2003 -0500, you wrote:
>SimpleDateFormat is not thread safe and if date formatting becomes a global
>resource then you are synchronizing a fairly expensive operation across the
>entire application. There are many reasons why you may want to format a date
>(logging, setting headers, etc.) on a per page basis and synchronizing on 
>every
>page request is not a good thing.


Vincent,

What you've suggested is certainly a possibility.  One thing I've noticed 
in profiling, however, is that the expensive part of creating a DateFormat 
object is the creation and not the actual formatting.  By caching and 
sharing date format instances (even synchronized), CPU time slices for that 
particular chunk of code dropped from 15% to 5%.  [Which is what I did in 
JDBC executor]

So given that, I think sharing a pool of SimpleDate instances would 
ultimately reap the highest performance, and sharing a single one would 
suffice over creating non-synchronized local copies up to considerable scaling.

Hope this clarifies!
                                                 -Mike







More information about the Opensource mailing list