-1

SimpleDataFomat is not thread safe and it is not recommended to use Synchronize in JEE. How to handle this in JEE ?

Thanks

Naren Karanam
  • 43
  • 1
  • 1
  • 10
  • 5
    1. just don't. Use the java.time api. 2. Just create a SimpleDateFormat when you need one. You seem to think that all thread-safety issues are solved using synchronized here and there. That's far from the truth. And there is no problem in synchronizing a piece of code that needs to be synchronized in Java EE. Don't know where you got that. – JB Nizet Sep 19 '16 at 06:01
  • i think this can help http://stackoverflow.com/questions/6840803/simpledateformat-thread-safety – LeonardoHAlmeida Sep 19 '16 at 15:09

1 Answers1

0

If you have to stick to the SimpleDateFormatter class don't share the SimpleDateFormatter object in a member variable but just create a new one inside the method to be on the safe side. Another approach is to put it in a ThreadLocal.

Wolkenfels
  • 43
  • 7