Running multiple instances of a run configuration: memory issues in Java
已回答
I've relatively new to Java and IntelliJ, and have developed an agent based model which takes a long time to run. I thought that running multiple instances in parallel would speed it up so I allowed multiple instances in the run configuration. I ran four instances, and one gave me a heap space error but the other three continued to run. A basic question: if I've set the JVM to have 4GB of memory available, do the four instances share that 4GB or does each instance have its own JVM with a limit of 4GB each? Likewise, with regards to cores: if I haven't changed any other default values will all instances run on a single core or will they be on their own cores?
请先登录再写评论。
Each instance/process will use the separate heap size, it's not shared.
Thanks for your reply! My computer has 32GB of RAM, should I then limit the amount of memory allocated to the JVM according to how many instances I plan to run? For example, if I'm running 4 instances then I should limit the memory to <8GB?
If you are referring to -Xmx setting, it's a maximum memory VM can allocate for heap, it doesn't mean that it will allocate all this memory when the app is started. The minimum memory is controlled by -Xms. Also note that total JVM process total memory usage can be higher than -Xmx: https://stackoverflow.com/a/13489882/104891. If you limit the max heap size to 4GB, you should be able to run 3-4 processes without swapping on 32GB system (note that OS itself will use a lot of your RAM).
Anyway, your questions are not IntelliJ IDEA specific and I would suggest using other resources to get advice from professionals.