Reputation: 325
I am running 2 instance of same application (using java - jar MyApp.jar) on same machine at a time. Inside one of my class I have created a class level variable (static). Will both applications share the same static variable as they are running under same JVM or separate JVM instance will created for both instances.
In case separate instances of JVM are created, either the class-loader loads 2 separate instances of My class which has static variable ?
I am not using any custom class loader*
Upvotes: 0
Views: 699
Reputation: 31605
If you call java - jar MyApp.jar
you will start a new JVM. This JVM loads its own classes, has its own memory and its own threads (and so on). It will not share anything with any other JVMs started before or after. Both JVMs are not connected to each other on any way. You just start your app twice.
Upvotes: 0
Reputation: 8323
No, they will not share the same variable.
Each process is allocated its own memory space and will not be able to access the memory of another process, unless IPC's or some other process communication protocol is used.
Upvotes: 1