Java: Do all processes run under the same JVM?

java

Solution

It is difficult to say precisely why the java processes are all exiting at the same time. It is not even clear why they are dying. To diagnose those problems, I would:

turn some GC logging; e.g. add the "-verbose:gc" command line option,

make sure that the application catches and logs exceptions that might be killing the 'main' thread, and

look in the processes current directory to see if they are leaving crash dumps.

But independent of that, when you run `java -jar -Xmx2000m ...` 20 times, you are staring 20 OS processes each of which could use in excess of 2Gb of virtual memory. On a machine with 4Gb of physical memory, this is simply crazy. Even if you have enough swap space (40Gb or more) to support that much virtual memory, the chances are that you will cause virtual memory thrashing before the heaps get anywhere like that big. When the system starts thrashing, system performance will drop through the floor.

To avoid this you need to make sure that the total virtual requirements of all active processes on the system is not much more than the physical memory that you have. Reduce the number of Java processes, reduce their maximum heap sizes or both. (And bear in mind that a JVM uses non-heap memory as well.)

Another thing that you should consider is rearchitecting your system so that it uses multi-threading within one JVM rather than using multiple JVMs. If implemented correctly, you should be able to get more throughput in a multi-threaded architecture because:

this avoids having multiple copies of the code and common data structures, so you have relatively more memory for useful heap objects,

the threads in a multi-threaded architecture can share caches of previously fetched objects, previously computed values, etc and

GC is more efficient with a single large heap than lots of smaller heaps,

Problem

We have a linux server that starts around 20 java programs. These java programs are all identical, except that they are using a differen port. These programs run fine. However, after a while all 20 programs crash at the exact same time. Each of these programs are allocated 2 gig of memory, by starting them up like this: java -jar -Xmx 2000m However, as far as we know, these programs do not get anywhere close near using these amounts of memories. The entire system has 4 gig of memory. SO, the question is, could on java program be responsible for crashing all 9 other ones? Is the VM shared, so that when it crashes, ALL java programs crash? Is there a log file I could possible check for a reason why java crashed? The java output did not show any error. EDIT: The strange thing is that this happened after a longer time, like 3 hours. These 20 processes had been running for quite some time before suddenly ALL crashing at the same time. And why do they ALL crash, if the java runtime starts it's own process for each program?

Original source

Related problems