在Java中,是程序之间共享的静态类成员吗? [英] In Java, are static class members shared among programs?

查看:168
本文介绍了在Java中,是程序之间共享的静态类成员吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想不,不是,因为每个进程都有自己的内存空间。

但是怎么做整个JVM实际上有用吗?对于我发布的每个Java程序,是否在单独的进程中有单独的JVM?在系统中运行的Java程序是否共享任何东西?操作系统和JVM实现之间是否存在差异?我可以使程序共享变量(即直接通过JVM而不是通常的IPC机制)吗?是否有更多异国情调的单进程JVM用于特殊目的?

But how does the whole JVM thing actually work? Is there a separate JVM in a separate process for every Java program that I launch? Do Java programs running in a system share anything at all? Are there differences between OSs and JVM implementations? Can I make programs share variables (i. e. directly through the JVM rather than the usual IPC mechanisms)? Are there more exotic one-process JVMs for special purposes?

一般来说,推荐哪些关于JVM的内容的读物? 规范?一些实现的源代码?网站?书籍?

Generally, what are recommendable reads about the guts of JVMs? The spec? The source code of some implementation? Websites? Books?

推荐答案


在Java中,静态类成员
是否在程序之间共享?

In Java, are static class members shared among programs?

一个类由其全名和加载它的类加载器定义。如果同一个类在同一个JVM进程中,并且两个程序通过相同的类加载器加载该类,则静态成员将被共享。类加载规则非常重要。

A class is defined by its full name and the class loader that loaded it. If the same class is within the same JVM process and the two programs loaded the class through the same class loader then the static members are shared. Classloading rules are of extreme importance.


我想不,它们不是,
因为每个进程都有自己的
内存空间,当然。

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

如果你使用两个独立的JVM来启动两个应用程序,那你就是对的。但是以tomcat的应用程序/ servlet容器为例:它们通过相同的进程(tomcat主机进程)加载多个应用程序。

If you are using two separate JVMs to launch two apps, you are correct. But take the case of application/servlet containers such as tomcat: they load several apps through the same process (the tomcat host process).


但整个JVM事物
实际上是如何工作的呢?对于我发布的每个Java
程序,在单独的进程中是否有单独的JVM
?在系统中运行的Java
程序是否共享
任何东西?

But how does the whole JVM thing actually work? Is there a separate JVM in a separate process for every Java program that I launch? Do Java programs running in a system share anything at all?

每次输入> java -cp ... 在命令行中,您正在创建一个新进程。请记住,当您运行eclipse或使用 fork = true 调用ant java任务时,您也在创建新进程。

Every time you type >java -cp... at the command line, you are creating a new process. Bear in mind that when you run eclipse or call an ant java task with fork=true you are also creating new processes.


操作系统和
JVM实现之间是否存在差异?我可以让
程序共享变量(即直接通过JVM的
而不是通常的IPC机制的
)?是否有
更具异国情调的单进程JVM,需要
特殊用途?

Are there differences between OSs and JVM implementations? Can I make programs share variables (i. e. directly through the JVM rather than the usual IPC mechanisms)? Are there more exotic one-process JVMs for special purposes?

就像海报上说的那样,有像Terracota这样的项目为您提供便利。这种共享的一般方法是分布式缓存。

Like a poster said, there are projects like Terracota that facilitate this for you. A general approach for this kind of sharing is a distributed cache.

这篇关于在Java中,是程序之间共享的静态类成员吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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