Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question regarding Normal Singleton Pattern vs. LazyLoad Singleton Pattern

 
Rahul Shivsharan
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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
Pie
Posts: 50211
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Too difficult a question for "beginning". Moving thread.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic