[Logo]
Forums Register Login
2 Java Programs on same Laptop
(1 like)
Each JVM is a separate process, and that means there is no sharing of stacks, heaps, etcetera. (Generally, the only things that might be shared are the read only segments that hold the code of the core JVM and native libraries ... in the same way that normal processes might share code segments)
The JVMs are independent processes. They don't share any mutable state. Garbage collection operates on each JVM independently.

Now suppose 2 java programs are running on same Laptop.If 1 program encounters java.lang.OutOfMemoryError: Java heap space

Will the 2nd program also get the same error ?




What have you tried, to answer that question?
Would the OS have any bearing on what happens?
Seems if you have 2 programs running on the same laptop and one of them eats up enough memory to get an out of memory error, I would think the other process would see the same fate eventually. There is only so much memory available on the system as a whole. Now I feel like trying it out on my laptop.
 

ere is only so much memory available on the system as a whole


I think a good OS would use paging to allow programs to access lots of "memory".  The total of the "memory" used by all the running programs would be much greater than the PC's memory.
 

Seymour Jones wrote:Seems if you have 2 programs running on the same laptop and one of them eats up enough memory to get an out of memory error, I would think the other process would see the same fate eventually. There is only so much memory available on the system as a whole.



But then what would happen if you opened (let's say) Excel and loaded in a spreadsheet of 30,000 rows? Would that maybe cause your Java program to crash because not enough memory was available?
 

Both the java programs would be using the same JVM ?


No. I think each execution of the java program would start its own JVM.  On Windows you can see separate processes by using the Task Manager.

On Windows there is some magic where the OS will give a running program a chance to open a file within an existing process.  For example open a PDF file in Adobe and then try to open a second PDF file, it will be opened in the running program in a new tab.
 

Norm Radder wrote:Would the OS have any bearing on what happens?

Probably yes, but I think most OSs would provide memory for each JVM as far as possible from the memory available.
 

most OSs would provide memory for each JVM as far as possible from the memory available.


It depends.    Perhaps the OS wants to reserve some free memory for other apps to use.
Then what happens when available memory is used up?
 

Norm Radder wrote:. . . Perhaps the OS wants to reserve some free memory for other apps to use.

That's what I meant about available.

. . .what happens when available memory is used up?

Same as what we remember from Windows98. It gets slower and slower because of paging and eventually the computer grinds painfully to a halt. Only nowadays, they have killed off the Blue Screen Of Death.
 

Norm Radder wrote:

Both the java programs would be using the same JVM ?


No. I think each execution of the java program would start its own JVM.  On Windows you can see separate processes by using the Task Manager.

On Windows there is some magic where the OS will give a running program a chance to open a file within an existing process.  For example open a PDF file in Adobe and then try to open a second PDF file, it will be opened in the running program in a new tab.




Thanks a Lot. You made my Day     
Now that that is settled, I'll mention a java program I wrote years ago when it took seconds/minutes to start a JVM.  The program has(I still use it) a list of my utilities that can be started to run in  the one JVM that the main program started.  It uses SecurityManager to trap calls to System.exit() to prevent any of the programs that are running from ending the JVM.  I wanted the same program to be able to run outside of this program without having to rewrite any of them  And it was a fun app to write.
Actually, the Sun/Oracle JVM has memory constraints such as the -Xmx parameter that limits allowable heap storage. So you're likely to blow Java's own memory controls before you run out of OS memory.

Speaking of which, OS memory, depending on the OS, can have quite a few constraints of its own. There's generally a per-process limit (for example, the Linux ulimit). Some OS's generate multiple address spaces, each of which has a finite limit, depending on the OS and the hardware. There are lots of things that can keep programs (JVM or otherwise) from eating each other.

Of course, that's predicated on having the necessary backing store. In a virtual memory system, you might have abundant virtual memory allocated, but if there's not enough physical RAM to back it - especially if you have cvery volatile working sets - then the machine may fall to a crawl and possibly even crash while the per-application memory quota has yet to be met.
Lasagna is spaghetti flvored cake. Just like this tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA


This thread has been viewed 256 times.

All times above are in ranch (not your local) time.
The current ranch time is
Aug 17, 2018 02:04:35.