• Post Reply Bookmark Topic Watch Topic
  • New Topic

Only one instance of class should be creatred  RSS feed

 
Laxmikant Kumbhare
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way in JAVA so that only one instance can be created of an application?
 
Ganesan Ponnusamy
MyExamCloud Support
Ranch Hand
Posts: 264
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use singleton pattern to achieve the same.

Typical example:



You can also implement singleton pattern in Java by using Enums.
 
Stephan van Hulst
Saloon Keeper
Posts: 7722
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks stephan !
 
Mike Okri
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may also want to take a look at the free JUnique library.
 
Laxmikant Kumbhare
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Okri wrote:You may also want to take a look at the free JUnique library.



What is it?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!