The call to DateFormat.format mutates internal state of the DateFormat object 
and will cause two concurrent format calls to mix up dates that are being 
formatted. We've had this happen at work. I think Jeppe is probably right that 
it should be a def (and therefore manufacture a new format each time)

-Ross

On Jan 11, 2010, at 4:25 PM, Naftoli Gugenheim wrote:

> Is it a problem if two threads *read* it at the same time? Is anything being 
> modified?
> 
> -------------------------------------
> Jeppe Nejsum Madsen<je...@ingolfs.dk> wrote:
> 
> Timothy Perrett <timo...@getintheloop.eu> writes:
> 
>> The whole Date class in Java is not thread safe. We considered swapping to 
>> JodaTime and I know DCB was working on it, but im not sure from the top of 
>> my head if he ever committed / merged what he was working on...
>> 
>> Cheers, Tim
>> 
>> On 11 Jan 2010, at 20:10, aw wrote:
>> 
>>> See:  
>>> http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html> 
>>> ---------------
>>> 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.
>>> ---------------
>>> 
>>> 
>>> Since SimpleDateFormat is not thread-safe, do I potentially have a bug
>>> when using TimeHelpers?
>>> 
>>> For example, see the Chat.scala example -- see "line" where it binds
>>> "when" -> hourFormat(c.when)...  Is there a potential problem there
>>> that multiple threads will be running the snippet and accessing the
>>> same underlying SimpleDateFormat?
> 
> Yes, I think it's a typo that hourFormat is a val an not a def (like the
> rest of the formats)
> 
> /Jeppe
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Lift" group.
> To post to this group, send email to lift...@googlegroups.com.
> To unsubscribe from this group, send email to 
> liftweb+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/liftweb?hl=en.
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Lift" group.
> To post to this group, send email to lift...@googlegroups.com.
> To unsubscribe from this group, send email to 
> liftweb+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/liftweb?hl=en.
> 
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to lift...@googlegroups.com.
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.


Reply via email to