-
Feb 8th, 2012, 05:04 PM
#1
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
-
Feb 8th, 2012, 05:18 PM
#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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules