7

I have a class that run infinit (do nothing, just loop and sleep), called NeverReturn. I try to run it using following command in Windows XP 32bit:

java -Xms1200M NeverReturn

I find with the command I can create only 4 java instance at same time. The 5th and next java command will failed to create jvm.

If I change the command to -Xms600M, I can create 8 java instance. The 9th will failed.

Could anyone explain that? I'm using sun jdk1.6 update 23 and jdk1.5 update 22.

xeranic
  • 1,391
  • 1
  • 9
  • 16
  • 4
    the 's' in -Xms force the JVM to allocate **at least** that much memory. Maybe you were thinking of '-Xmx', with an 'x', that will allocate **at most** that much memory. If your machine has 6 GB, then what you're seeing is totally normal seen that you used '-Xms'. – Gugussee Jan 13 '11 at 09:37
  • The 32bit XP version can only handle 4GB - and afaik the there are only around 3GB available in that case. – tigger Jan 13 '11 at 10:28
  • 1
    I understand the difference between the -Xms and -Xmx. My question is OS have ability to give every process about 2GB memory on 32bit windows system. But why there are still some limiation cross these jvm process. – xeranic Jan 14 '11 at 02:56

3 Answers3

6

If you have four instances of the JVM each using 1200M of memory, that gives you 4800M of memory allocated.

If you have eight instances of the JVM each using up to 600M of memory, that gives you 4800M of memory as well.

If I had to guess, it looks like the problem is that you're trying to promise more memory to the JVM instances than exists on your system. Dropping the amount of memory you promise should have a corresponding increase in the number of instances you can run.

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
  • +1. Yes, the JDK checks if there is enough memory to guarantee the -Xms (and other related) settings. – Thilo Jan 13 '11 at 09:09
  • 2
    The JVM allocate a continuous block of memory on startup. It will fail if there is no more memory+swap left. – Peter Lawrey Jan 13 '11 at 09:33
2

Simple answer: as many JVMs as you want; of course as long as your machine can provide the necessary resources (read memory).

If you wanted to ask how many JDK/JREs you can use in a machine (different JDK/JRE versions); the answer is "there is no constraint".

So you can have many JDKs as well, I am not sure of the windows installers though. You can always choose to use a dump instead.

Hope this helps.

Ayusman
  • 8,509
  • 21
  • 79
  • 132
  • However the truth I see is there are some limiation at the total memory of many jvm instances. But that limitation does not exist on other process. – xeranic Jan 14 '11 at 02:59
0

For every instance of the virtual machine launched in this way, 600 MB of memory is dedicated to it, meaning if you only had 1 GB of memory, you could only successfully launch one instance of JVM if you allowed each instance to consume 600 MB of memory. By the sounds of it, you had roughly 4.6 GB of memory free at the time of running 8 instances of 600 MB each.

Neil
  • 5,762
  • 24
  • 36