• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

singleton class  RSS feed

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
What is singleton class;anybody give me one example? When multiple users want to access that class how will u do that?
bye
chaitanya
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A singleton class has a limited (usually 1) number of instances and are accessed statically using static methods or a combination of instance methods and a static getInstance() accessor method.
Access to a singleton class method by multiple threads simultaneously is handled just like for any other kind of class -- if the method ain't synchronized, everybody gets "in". If the method is synchronized, the JVM serializes the invocations and lets each of them execute the method in turn.
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's another good link: http://c2.com/cgi/wiki?SingletonPattern
A very simple example of singleton is:
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best example for singleton pattern in J2SE is java.lang.Runtime class.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See also http://www.javaranch.com/newsletter/July2003/SaloonQnAOfTheMonth.html
 
It's just a flesh wound! Or a tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!