The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Anurag priya
SCJP 2(83%); Brain Bench Certified for: Masters level EJB2.0(97%) - Masters level J2EE (83%) - BEA-WebLogic Application Server8.1 (86% )
Seetesh:
User should create only one instance of the "class"
Originally posted by anurag priya:
Just make everything in the class as static (methods , attrubutes ), so it doesn't matter how many instances are created still all will be refereing to only one instance .
thats the simplest way of doing it .
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Seetesh Hindlekar:
My requirement is finding an alternate solution to the Singleton pattern so that I can implement the same for restricting any thin clients trying to access the object created so that only one client has access to the Class defined. (Something like implementing a SingleThreadModel concept)
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Seetesh Hindlekar:
=========================================
If this is what you want, the Singleton pattern is the way to enforce that constraint. However, you should consider if there really is a strict requirement to enforce the constraint technically -- a "soft" guidance for developers to "just create one" is often a good enough solution, although it does run the risk of someone indeed creating two instances of the class.
============================================
Is Singleton the only solution? No other way around to achive the same!
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Originally posted by Seetesh Hindlekar:
Singleton pattern is normally applicable to a single client application trying to instantiate a Class ie trying to instantiate this class more than once in its execution path.
Originally posted by Seetesh Hindlekar:
I am looking something like 'n' nos of clients trying to instantiate this class object. So only one client should be able to instantiate this class while others should get a message that the class is already instantiated by some other client.
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
I am looking something like 'n' nos of clients trying to instantiate this class object. So only one client should be able to instantiate this class while others should get a message that the class is already instantiated by some other client.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Seetesh Hindlekar:
The application to be designed is supposed to take care of this multiple clients modifying the "source" and thats why we need to implement the instantiation of the class.
Also to add to this application, we are not using any web services or app servers. Its just a application to be developed and to be installed on our server allowing clients to invoke the same but at a time only one client will do the updation.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Stan James:
For multiple JVMs you're going to have to find some kind of external lock.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Jeremy Thomerson<br />Software Engineer, eBay, Inc.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |