This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Possible to spin off independant JVM?

 
Matt Senecal
Ranch Hand
Posts: 255
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Dale DeMott
Ranch Hand
Posts: 515
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Matt Senecal
Ranch Hand
Posts: 255
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic