• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Two instances sharing memory ?

 
Ranch Hand
Posts: 198
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 198
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 198
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Honk if you love justice! And honk twice for tiny ads!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic