SCJP 1.5
Originally posted by ArpitSharma:
suppose i am having one singleton object in one jvm ,how do i maintain the same copy of singleton across different JVMs
Originally posted by shiva shankar:
Maneesh - Remote call is not a viable solution for this issue in distributed environment.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Originally posted by Rob Prime:
Because each JVM has its own singleton instance. Static fields are only unique per Class instance, and using a different class loader (which will always be the case with a different JVM) will create a new Class instance, and therefore new static fields.
Hmm.
I was thinking of a different scenario.
You got some applications running on machine A and B.
When required these applications make a remote call to machine C and ask for the singleton instance.
That way the same instance would be shared accross multiple JVMs right?
Originally posted by prashant bhardwaj:
So, you are saying that only machine C has the Singleton while A and B don't?
I do not think that just to get a "Singleton" it is wise to configure your machines in a contrived scenario that you've presented.
All machines have the same code. But A and B ask C for the instance.
All machines have the same code. But A and B ask C for the instance.
The point here is not to "get" a singleton but to share it accross JVMs
So whenever the singleton instance is required, everybody asks C
Similar stuff is done every day by lots of people (think web.xml or config file or properties or anything that catches your fancy).
Well, A would be told where C is, perhaps by some configuration file or by a JNDI lookup or something. I don't see why this is such a difficult business. Nobody complains about having to tell the database clients where the database is located, so why should it be different for this C resource?Originally posted by prashant bhardwaj:
I'd like to be educated about it.How one machine(say A) in a cluster would identify another machine (C in this case) to make a call for a Singleton ?
Well, A would be told where C is, perhaps by some configuration file or by a JNDI lookup or something. I don't see why this is such a difficult business. Nobody complains about having to tell the database clients where the database is located, so why should it be different for this C resource?
He was expelled for perverse baking experiments. This tiny ad is a model student:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|