Multiple calls jvm through JNI result in massave memory usage
posted 3 years ago
I have a java program that is distributed through a jar file that can be run by itself, or is wrapped by a C++wrapper to be a windows service. The C++ code does next to nothing, it just takes the arguments sent in and calls the jvm.dll to launch the jar file passing in the options. The Java jar does all the actual work.
We support multi threading my launching multiple services/jar files.
Running multiple jar files through the command line works as expected, with each process having the same memory footprint and working the same.
When I run them as windows services, I get two different results based on how Ii start them.
if I start each service and wait till it is completely started before starting the next service, I see normal memory consumption.
if I start them as fast as I can, like how it normally would happen when starting up a machine, then memory consumption is much larger, I am seeing 5X the memory used. 300MB vs 1.5 GB. I can recreate this on windows 7, server 2003, and server 2008 so it does not appear to be anything with a particular system. I can't recreate this using the jar file alone. I have tried passing in a number of parameters to java to limit memory or force garbage collection as I think it is the memory that is being allocated to the jvm process that is the culprit as this only happens when the jvm is launching the process all at the same time, but have not found anything to get the memory allocation to be normal size. Does anyone have any idea what could be causing this? I have played around with a number of memory tools and search for a cause/fix for this online, but have not found anything similar to this.