Announcement Announcement Module
Collapse
No announcement yet.
Do I have to worry about thread safety of the methods of singletons in the container? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Do I have to worry about thread safety of the methods of singletons in the container?

    I'm planning on wiring up services and controllers in my container. Do I need to make all of the service methods synchronized since all controller threads will be using a single instance of each service?

    I realize I could configure the container to deliver a new instance each time. What I'm confused about is what is the developers responsibility for singletons, i.e. do they need to have synchronized methods in order to be thread safe.

    Thanks,
    bills

  • #2
    It depends on the service and the implementation of the service methods. If the class has no instance data, then you're pretty safe. If the only instance data is only set at bean initialization time, then you're still pretty safe. Past that, you have to examine the usage scenarios to see if you need to synchronize any critical sections to prevent data corruption.

    Comment

    Working...
    X