tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David kerber <dcker...@verizon.net>
Subject Re: Trouble parsing datetime strings
Date Mon, 11 May 2009 14:22:13 GMT
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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message