Confusion about thread safety - SimpleDateFormat example

后端 未结 7 992
野的像风
野的像风 2021-01-02 03:57

I have a question about thread safety. From what I have been told, SimpleDateFormat is not thread safe. I was wondering what effects it would have if I use it the followin

相关标签:
7条回答
  • 2021-01-02 04:50

    So what kind of problems will I see using it this way?

    Developers of SimpleDateFormat took a very strange decision - during work of parse() they store partially parsed date in a field of SimpleDateFormat. Obviously, it means that you can't call parse() from several threads simultaneously.

    Would simply removing the static keyword fix any issues because then each thread will use its own instance of dateFormat?

    Removing static won't help you, since Spring controllers are singleton scoped by default, so Spring uses a single instance of your controller to serve all requests.

    0 讨论(0)
提交回复
热议问题