简体   繁体   中英

Share classes between JVMs

I'm working on an application that can be instanciated several times in the same computer, at the same time. Each JVM loads the applications classes in their own memory unnecessarely, since the classes are the same for all the applications.

I read about CDS here and here , but it seems to be valid only to the JDK classes.

How can I share my application classes' data between the JVMs?

I was not particularly abreast of this topics but I did some research. I think we can say with considerable certainty that it is not practically possible in most JVM's. The question below is similar to yours and it has answers and comments that may be helpful.

Can multiple JVM processes share memory for common classes?

A possible option is you could put the classes you would like to share together in one process and expose their functionality using something like JMX (Java Management Extensions). That way the other processes that are loaded several times would not have to load all the classes. But how much this can reduce the total resource footprint is of course questionable and case dependent.

While it sounds good in theory, this isn't really practical. The storage image of a Java class consists of a certain amount of constant data, but probably just as much "variable" data -- linkage pointers to other classes, various runtime tables, JITCed code, etc. Figuring out what's sharable and what isn't is difficult at best and leads to designs that do not produce the best performance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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