In Java, are static class members shared among programs?

前端 未结 7 2009
独厮守ぢ
独厮守ぢ 2020-12-15 19:38

I imagine that no, they aren\'t, because every process has its own memory space, of course.

But how does the whole JVM thing actually work? Is there

7条回答
  •  温柔的废话
    2020-12-15 20:30

    No, static variables aren't between JVMs. Yes, there's a separate JVM process for each Java app you run.

    In some implementations I believe they may share some resources (e.g. memory for JITted code of JRE classes) but I'm not sure. I believe there's ongoing work to enable more sharing, but still in a robust way. (You don't really want one JVM crashing to affect others.)

    No, you can't make programs share variables transparently.

    I believe there are books about the JVM, but I can't recommend any. You'd probably be best off looking for HotSpot white papers for details of that. This one is a pretty good starting point.

提交回复
热议问题