Konstantin Kolinko wrote:
...
As the JavaDoc says
http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html
"Date formats are not synchronized. It is recommended to create
separate format instances for each thread"
You may either create a new instance of SimpleDateFormat each time, or
add a synchronization around that part of code, or use a ThreadLocal
(though ThreadLocal has its own caveats as the threads belong to
Tomcat and are shared among applications).
Without profiling you would not know which one of the ways I am
mentioning is faster.
Maybe I would start with creating a new instance each time, as GC for
short-living objects seems to be cheap in recent JREs. Though without
profiling you will not get the numbers.
Thanks, guys! Obviously I missed that part when I was looking for a fix
for this issue. For now, I took the simplest (from a coding standpoint)
way out, and moved the declaration of the SimpleDateFormat into each
method where it's used, and that has fixed the issue. From the quick
reading I did, I imagine that will give me a bit of a performance hit
compared to using ThreadLocal, but since I've never used the ThreadLocal
pattern before, I didn't want to try implementing it on the fly, just to
fix this issue. As for whether synchronization would be faster than
local declaration, I'll try doing some benchmarking at some point.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org