aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 36453
    
  15
Too difficult a question for "beginning". Moving thread.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18110
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question regarding Normal Singleton Pattern vs. LazyLoad Singleton Pattern
 
Similar Threads
creating a list of subsets from N elements
Combination Generation...
Static reference for object
How do i get all subsets?
customized constructors