aspose file tools*
The moose likes Java in General and the fly likes Possible to spin off independant JVM? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Possible to spin off independant JVM?" Watch "Possible to spin off independant JVM?" New topic
Author

Possible to spin off independant JVM?

Matt Senecal
Ranch Hand

Joined: Dec 01, 2000
Posts: 255
I have a program (MyProgram) that launches other java programs and runs them all on the same JVM (the one that MyProgram is running on). As many of you are aware, same-JVM execution is like one huge memory leak: when one program on the JVM quits, not all of it's resources are reclaimed.
One proposed solution to this problem was to have MyProgram create a new JVM (different from the one it's running on) for the programs it launches to run on. Every 3rd program it would release the previous JVM (leaving it to run on it's own) and create a new one to run the next 3 launched programs on.
Is this possible? (If I'm not making sense, please let me know)


There's nothing more dangerous than a resourceful idiot. ---Dilbert
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
Why would this be a memory leak? "Memory Leaks" happen when an object is not dereferenced when an object is no longer used. Maybe we need more info here. I'm not sure I understand the structure that you are using. Are you using threads or are you just running more applications off of the main program?

------------------
By failing to prepare, you are preparing to fail.
Benjamin Franklin (1706 - 1790)


By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
Matt Senecal
Ranch Hand

Joined: Dec 01, 2000
Posts: 255
The setup is that MyProgram displays a bunch of buttons that are associated with other Java programs. When a button is pressed, the classes needed to run that application are loaded (using URLClassLoader) and an invoke() is called on the main class of that application. This executes the selected application on the same JVM that MyProgram is running on. There may be a better way to do this.
Why do I call this a "leak"? Lets say MyProgram is running by itself, and the JVM needs 4MB of RAM. I run "TreeTest". The memory needed by the JVM increases from 4MB to 5MB. I later quit "TreeTest", and the memory required by the JVM only falls by 200k, meaning that 800k of the momory reserved for the execution of TreeTest hasn't been reclaimed. This memory is (obviously) no longer available to any application. This doesn't sound like a lot, but some of the applications we use grab 20MB of RAM to execute. When only 1MB (or less) of that is reclaimed, that's a huge loss.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
How do you measure the memory required? The JVM will not give all its allocated memory back to the OS straightaway (the heap may remain fragmented). Some of the memory consumption will be loaded classes, I'm not sure when they will be unloaded. In short, don't draw conclusions too quickly.
Try running a few programs in this way, a few times each, and see what happens to your memory usage then. It probably won't be half as bad as you think.
- Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Possible to spin off independant JVM?
 
Similar Threads
Q on Threads
Number of JVMs in a CPU
JVM Question...
JVM, how it works?
Error Handling