667481 members! Sign up to stay informed.

Sponsored Links


Resources

Enterprise Java
Research Library

Get Java white papers, product information, case studies and webcasts

Blogs Blogs Blogs Messages: 2 Messages: 2 Messages: 2 Printer friendly Printer friendly Printer friendly Post reply Post reply Post reply XML XML XML

Problems with design pattern "Singleton"

Posted by: Regina Lynch on July 28, 2006 DIGG
The use of the design pattern "Singleton" is very common and the common implementation is using a static reference. However, according to Guy Korland, the problem with this implementation is that many times it leaves "floating garbage that is not in use."

As a better solution, Joshua ben Jore has introduced WeakSingleton. This extention cleans the instance when all other references to the original instance have expired.
  Message #215240 Post reply Post reply Post reply Go to top Go to top Go to top

Singleton Pattern's possible pitfalls

Posted by: Swapnil Jagtap on August 09, 2006 in response to Message #214439
Singleton is a commonly (mis) used design pattern.
Users of this pattern should be aware of the scope & lifecycle control of the singleton object.

Singleton could be at various scope levels.
1. Singleton object within a operating system environment or JVM.

2. Singleton object across clustered environments.
It may not be considered singleton from application's perspective.

3. Singleton in a multi-threaded application.
It should be thread safe for which programming Idioms are available.

  Message #217641 Post reply Post reply Post reply Go to top Go to top Go to top

Warning: Not threadsafe

Posted by: James Watson on September 11, 2006 in response to Message #214439
The code given is not threadsafe and using volatile with 1.5 may not solve the problem.

Featured SectionFeatured SectionFeatured Section
Weekly Blogs UpdateWeekly Blogs UpdateWeekly Blogs Update
Stay current on the most informative blogs in the enterprise Java community. Join TheServerSide.com and sign up for the Blogs Update. Let TheServerSide.com do the work for you -- we scan thousands of blogs to find the ones most worthy of your attention.
Featured BlogsFeatured BlogsFeatured Blogs

Optimizing CMP Performance in Weblogic with Long-term Caching

Dmitri Maximovich has written a blog on optimizing CMP EJB performance in WebLogic, by addressing optimistic concurrency, along with some of the implications of doing so.

Using Lucene with OJB

Brian McCallister looks at the Lucene search engine and shows us how to index and retrieve objects from a sample Student application.

JDK 5 in Practice

Cedric Beust has been in a position to actually code with JDK 5 for over six months. He has written up his thoughts on the new features, and how he has found them to be in practice.

Dear Manager, They Need a Build Machine

Mike Clark has started a series of entries of letters that you wish you could write to your boss. It consists of concepts which seem so obvious to us, but which the bosses don't get.

Are we doing OR mapping wrong?

Brian McCallister has been playing with JDO 2 fetch groups, ZODB, thinking about TranQL, playing with Prevayler, and looking at TORPEDO.

Fear and Testing

Frank talks about fear and how it can derail efforts to find and solve scalability and performance problems. He has seen a lot of fear on his various engagements, and here he talks about why, and how.

Components, Design, and Functions

Brian McCallister has kindly rambled on about IoC, and design in web applications. He discusses what has worked well for him (and others) in the last year.

JDK 1.5 from Joshua and Neal

Matt Raible went to the Denver JUG meeting with Neal Gafter, and Joshua Bloch. They discussed the new features of Java 5, and Matt details the features, and when to use them.
Featured Blogs Archive

News | Blogs | Discussions | Tech talks | Patterns | Reviews | White Papers | Downloads | Articles | Media kit | About
Java Solutions
All Content Copyright ©2007 TheServerSide Privacy Policy
Site Map