Meaningless Drivel is fun!*
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: 39044
    
  23
Too difficult a question for "beginning". Moving thread.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    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.
 
GeeCON Prague 2014
 
subject: Question regarding Normal Singleton Pattern vs. LazyLoad Singleton Pattern