aspose file tools*
The moose likes Performance and the fly likes Only one instance of class should be creatred Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Performance
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: 38
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 | Test Generator | OCAJP | OCPJP | OCEJWSD | EJB Certification
OCEJPAD | SCJD | SCWCD | SCBCD | SCDJWS | OCMJEA | Web Services Certification | SCMAD
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3649
    
  17

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: 38
thanks stephan !
Mike Okri
Ranch Hand

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

Joined: Sep 19, 2011
Posts: 38
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: 6109
    
    6

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Only one instance of class should be creatred