多个JVM进程可以共享公共类的内存吗? [英] Can multiple JVM processes share memory for common classes?

查看:664
本文介绍了多个JVM进程可以共享公共类的内存吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Web服务器上运行多个Java进程,每个Web应用程序一个.我正在使用一个具有很多支持类和jar文件的Web框架(播放),并且Java进程占用了大量内存.一个Play进程显示大约225MB的驻留私有"内存. (我正在使用Java 1.7.0_05在Mac OS X上对此进行测试.)特定于应用程序的代码可能只有几MB.我知道典型的Java Web应用程序是添加到一个服务器进程(Tomcat等)中的jar,但是运行Play的标准方法似乎是作为独立的应用程序/进程.如果这些是C程序,则这200MB中的大部分将是共享库,并且不会在每个应用程序中重复.有没有办法做到这一点在Java中?我看到了一些有关类数据共享的页面,但这似乎仅适用于核心运行时类.

I'd like to run multiple Java processes on my web server, one for each web app. I'm using a web framework (Play) that has a lot of supporting classes and jar files, and the Java processes use a lot of memory. One Play process shows about 225MB of "resident private" memory. (I'm testing this on Mac OS X, with Java 1.7.0_05.) The app-specific code might only be a few MB. I know that typical Java web apps are jars added to one server process (Tomcat, etc), but it appears the standard way to run Play is as a standalone app/process. If these were C programs, most of that 200MB would be shared library and not duplicated in each app. Is there a way to make this happen in Java? I see some pages about class data sharing, but that appears to apply only to the core runtime classes.

推荐答案

目前,对于Oracle VM,这是不可能的.

At this time and with the Oracle VM, this isn't possible.

但是我同意,这将是一个不错的功能,特别是因为Java拥有自动执行此操作所需的所有信息.

But I agree, it would be a nice feature, especially since Java has all the information it needs to do that automatically.

最重要的是,我认为JIT是无法正常工作的唯一原因:JIT考虑了运行时行为.因此,如果应用程序A使用与应用程序B不同的模式中的某些代码,则将导致在运行时生成不同的汇编器代码.

Of the top of my hat, I think that the JIT is the only reason why this can't work: The JIT takes runtime behavior into account. So if app A uses some code in a different pattern than app B, that would result in different assembler code generated at runtime.

但是,通常的模式"是多久使用一次此代码".因此,如果应用程序A经常调用某种方法而应用程序B却没有,他们仍然可以共享代码,因为应用程序A已经付出了优化/编译的代价.

But then, the usual "pattern" is "how often is this code used." So if app A called some method very often and B didn't, they could still share the code because A has already paid the price for optimizing/compiling it.

您可以尝试的是将多个应用程序作为WAR文件部署到单个VM中.但是从我的经验来看,这通常会导致代码无法正确清理线程本地或关闭钩子的问题.

What you can try is deploy several applications as WAR files into a single VM. But from my experience, that often causes problems with code that doesn't correctly clean up thread locals or shutdown hooks.

这篇关于多个JVM进程可以共享公共类的内存吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆