This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Question regarding Normal Singleton Pattern vs. LazyLoad Singleton Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Question regarding Normal Singleton Pattern vs. LazyLoad Singleton Pattern" Watch "Question regarding Normal Singleton Pattern vs. LazyLoad Singleton Pattern" New topic
Author

Question regarding Normal Singleton Pattern vs. LazyLoad Singleton Pattern

Rahul Shivsharan
Ranch Hand

Joined: Jun 17, 2009
Posts: 83



In the above code i made a singleton class SingletonObject01.java, which gives single instance of it in multithreading environment also

now if i use Lazyload singleton as below,



This also gives the only one instance of class SingletonObject02.java that too in multithreading enviroment

Now,
My question is in my both of above approach i am not using synchronized key work ,
So which approach is better for Singleton Pattern from above two



Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 43984
    
  33
Too difficult a question for "beginning". Moving thread.
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19728
    
  10

Which is better? I would say the first is better, because it's shorter and easier to understand.

In terms of execution time and resources and so on, both of them are trivial code which do essentially nothing and consume essentially no resources, so there is hardly any difference between the two.
 
Have you checked out Aspose?
 
subject: Question regarding Normal Singleton Pattern vs. LazyLoad Singleton Pattern
 
jQuery in Action, 3rd edition