Hi all,
I have a doubt while developing a J2EE system.
We are using Struts, and as I know Struts have pools for Actions, servlets ... It is all designed to work with multiple threads.
But as oposite to this we use very often the singelton pattern, for utility classes in most cases.
Here comes my suspition, if we have pools of actions and servlets, why we dont create pool of objects for this utility classes but use single instance for all the threads.
My oppinion is that if you use the singleton pattern very often it may create a bottelneck especially in a multiprocessor system when many processors work concurently but fight for only one singleton instance.
What do you think?
Regards
-
Can The usage of the Singleton pattern create bottleneck in J2EE (1 messages)
- Posted by: Ridvan Gyundogan
- Posted on: April 04 2006 03:54 EDT
Threaded Messages (1)
- Can The usage of the Singleton pattern create bottleneck in J2EE by Rod Johnson on April 04 2006 06:38 EDT
-
Can The usage of the Singleton pattern create bottleneck in J2EE[ Go to top ]
- Posted by: Rod Johnson
- Posted on: April 04 2006 06:38 EDT
- in response to Ridvan Gyundogan
Singletons will only reduce concurrency if the relevant methods are synchronized. There is no limit to the number of threads that can concurrently execute in a threadsafe object. In fact, if your objects are naturally threadsafe, a shared non-synchronized object will outperform any pooling strategy, as there can never be contention.
Struts does not use action pooling, btw. And the "SingleThreadModel" approach to servlets, that used a pool rather than a single instance, is now deprecated.
Rgds
Rod Johnson, Interface21 - Spring from the Source