简体   繁体   English

一个程序中有多个JVM实例

[英]Multiple JVM instances in one program

I have a JFrame and a JTabbedPane 我有一个JFrame和一个JTabbedPane

The JTabbedPane has JPanel s, and each JPanel has an Applet . JTabbedPane具有JPanel ,每个JPanel具有Applet

If I load the applet, and then close it, the CPU usage drops but the RAM usage stays high. 如果我加载小程序,然后将其关闭,则CPU使用率下降,但RAM使用率仍然很高。 So in order for me to correctly release the RAM, each JPanel / Applet has to have its own JVM which I can terminate. 因此,为了让我正确释放RAM,每个JPanel / Applet必须有自己的JVM,可以终止它。 The code of the Applet isn't mine, but that's how it was made, simply destructing it won't work. Applet的代码不是我的,但是那是它的制作方式,仅仅破坏它是行不通的。

So what I'm asking is, how can I attatch a new JVM to each JPanel as I add one? 那么,我问的是,我怎么能attatch一个新的JVM每个JPanel我添加一个?

In order to accomplish this you would need to have a wrapper application capable of starting a new instance of the JVM (forking a new process) each time you want to open one of your JPanel/Applet things. 为了实现这一点,您每次需要打开一个JPanel / Applet组件时,就需要有一个包装器应用程序,该应用程序能够启动JVM的新实例(派生一个新进程)。 You could do this by calling Runtime.exec() and invoking a new instance of the JVM, but honestly all of this smells a little bit to me. 您可以通过调用Runtime.exec()并调用JVM的新实例来做到这一点,但是老实说,所有这些对我来说都有些气味。 The JVM really isn't designed for this and I think what's more likely is you have a memory leak somewhere that isn't properly handled. JVM确实不是为此设计的,我认为更有可能的是您的内存泄漏在未正确处理的地方。

I don't think you can have more than 1 instance of the JVM running for any given application, as detailed by the Runtime Class 我不认为您可以为任何给定应用程序运行超过1个JVM实例,如Runtime Class所详述

However, I believe if you remove all of your references to each Applet when you shut it down, you can call System.gc() to clean up the memory so that you can use it for something else within that Java application. 但是,我相信,如果在关闭每个Applet时都删除了对所有Applet的引用,则可以调用System.gc()清理内存,以便可以将其用于该Java应用程序中的其他内容。 However, keep in mind that your RAM usage will not go down, as the JVM heap is allocated at startup and, so far as I know, cannot be resized during execution. 但是,请记住,由于JVM堆是在启动时分配的,并且据我所知,执行期间无法调整其大小,因此RAM的使用不会下降。 For information on how that works, see JVM Option: Xmx Allocation 有关其工作方式的信息,请参阅JVM选项:Xmx分配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM