0

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*

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.