Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

2 Java Programs on same Laptop  RSS feed

 
Ranch Hand
Posts: 227
Eclipse IDE IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?




 
Marshal
Posts: 58345
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you tried, to answer that question?
 
Rancher
Posts: 2862
32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would the OS have any bearing on what happens?
 
Greenhorn
Posts: 19
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Norm Radder
Rancher
Posts: 2862
32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 23451
46
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
Norm Radder
Rancher
Posts: 2862
32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Campbell Ritchie
Marshal
Posts: 58345
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Norm Radder
Rancher
Posts: 2862
32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
Campbell Ritchie
Marshal
Posts: 58345
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Santosh Kumar Nayak
Ranch Hand
Posts: 227
Eclipse IDE IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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     
 
Norm Radder
Rancher
Posts: 2862
32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 19266
85
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!