Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 205
Daniel Pereira Avatar asked Dec 18 '12 18:12

Daniel Pereira


2 Answers

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.

like image 184
Marquez Avatar answered Sep 23 '22 16:09

Marquez


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.

like image 44
Hot Licks Avatar answered Sep 23 '22 16:09

Hot Licks