aspose file tools*
The moose likes Beginning Java and the fly likes Two instances sharing memory ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Two instances sharing memory ?" Watch "Two instances sharing memory ?" New topic
Author

Two instances sharing memory ?

Manoj Kumar Jain
Ranch Hand

Joined: Aug 22, 2008
Posts: 191

Hi all,

I have one desktop application which is having a lots of variables in classes as public static. This application facilitate user to declare some variable/provide input in fields to do the calculation. These variables/fields are stored as static variables internally in code. Some time user complaints that when two/more instances of same application run on a machine these variables get messed up with each other. I talked to one guy and he said that there is a single JVM for all the instances and static variables are common for all the instances. which is causing the trouble.

However I am not agree with this concept because if this is the case then why these variables don't get messed up every time.
I hope my query is clear. Can you please suggest something.

Thanks in advance
Manoj


Do not wait to strike till the iron is hot; but make it hot by striking....
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Manoj Kumar Jain wrote:Hi all,

I have one desktop application which is having a lots of variables in classes as public static.


That's bad design.

Some time user complaints that when two/more instances of same application run on a machine these variables get messed up with each other. I talked to one guy and he said that there is a single JVM for all the instances and static variables are common for all the instances. which is causing the trouble.


No, that's not what's happening. Unless maybe you have some specialized, niche JVM like on a microcontroller or something.

However I am not agree with this concept because if this is the case then why these variables don't get messed up every time.
I hope my query is clear. Can you please suggest something.



Don't look for exotic causes like two JVMs overwriting each others' variables. Assume there's a bug in your code, find it, and fix it.
Manoj Kumar Jain
Ranch Hand

Joined: Aug 22, 2008
Posts: 191

Thanks Jeff for your reply !

Yes, we have a bad designed application.
No, we don't have anything like micro controller or something. Its swing based GUI.
Yes, I am looking into the code to get it fixed, but I still have query that do there exist different JVMs on the system for the different instances of the same desktop application or there is common JVM for all the instances.
Do JVM behave like servlets in context (like one servlet instance exist for a JVM in web app but multiple users/client get served by different thread using same servlet instance.) of sharing.

Please resolve my curiosity

Thanks
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Manoj Kumar Jain wrote:I still have query that do there exist different JVMs on the system for the different instances of the same desktop application or there is common JVM for all the instances.


Do you invoke the "java" executable only once? If so, then there's only one JVM running.

Or do you invoke the "java" executable separately for each instance? If so, then each insance has its own JVM, and its own memory, and they're not sharing any variables.

Manoj Kumar Jain
Ranch Hand

Joined: Aug 22, 2008
Posts: 191

Yes, I am invoking the java executable for each instance. so, I am having different JVM for each instance.

Thanks a lot Jeff for clearing my doubt.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Two instances sharing memory ?
 
Similar Threads
User name display problem
Static variables and running the same class twice
final static variables in beans?
serializable problem
Static vs. Final