The moose likes Performance and the fly likes Only one instance of class should be creatred Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Performance
Reply Bookmark "Only one instance of class should be creatred" Watch "Only one instance of class should be creatred" New topic
Author

Only one instance of class should be creatred

Laxmikant Kumbhare
Ranch Hand

Joined: Sep 19, 2011
Posts: 37
Is there any way in JAVA so that only one instance can be created of an application?
Ganesan Ponnusamy
EPractice Labs Support
Ranch Hand

Joined: Nov 07, 2005
Posts: 249
You can use singleton pattern to achieve the same.

Typical example:



You can also implement singleton pattern in Java by using Enums.


Ganesan Ponnusamy Java Certification Preparation | Test Generator Software | OCAJ7 | OCPJP7 | OCEWebServices | OCEEJB
OCEJPA | SCJD | SCWCD 5 | SCBCD 5 | SCDJWS 5 | SCEA Part1 | SCEA Part 23 | SCMAD
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 2771

The original poster probably wants one instance of the application, not of a class.

Take a look at this article: http://www.rbgrn.net/content/43-java-single-application-instance
Laxmikant Kumbhare
Ranch Hand

Joined: Sep 19, 2011
Posts: 37
thanks stephan !
Mike Okri
Ranch Hand

Joined: Jun 22, 2011
Posts: 74
You may also want to take a look at the free JUnique library.
Laxmikant Kumbhare
Ranch Hand

Joined: Sep 19, 2011
Posts: 37
Mike Okri wrote:You may also want to take a look at the free JUnique library.



What is it?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 3133
Laxmikant Kumbhare wrote:
Mike Okri wrote:You may also want to take a look at the free JUnique library.



What is it?


Click the link and find out.
 
IntelliJ Java IDE
 
subject: Only one instance of class should be creatred
 
Threads others viewed
Two sync methods of same class called by two threads
wrong names in assignment
POJO class + Singleton
if there is 1 RAF instance, then why lock??
Anonymous Class Implementation
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com