简体   繁体   English

为什么在Java EE Application Server中使用单个JVM实例?

[英]Why Single JVM instance in Java EE Application server?

I want to ask that if we run a standalone java application using the java command, for each application a new instance of a JVM is created with a separate heap etc. 我想问一下,如果我们使用java命令运行独立的Java应用程序,则为每个应用程序创建一个带有单独堆等的JVM新实例。

  1. But why in a Java EE application server is there only one JVM instance for each ear or war file deployed on the application server instance? 但是,为什么在Java EE应用程序服务器中,对于部署在应用程序服务器实例上的每个Ear或war文件,只有一个JVM实例?
  2. Why we are using separate class loader for each application to distinguish between application instead separate JVM instance.? 为什么我们为每个应用程序使用单独的类加载器来区分应用程序而不是单独的JVM实例?
  3. Does Single JVM instance is required in App server to manage life cycle of servlet,jsp and ejb etc? App Server是否需要单个JVM实例来管理servlet,jsp和ejb等的生命周期?

Suppose you have start the application server like oracle or jboss it takes one instance of jvm bacause you have configure the jvm tuning properties into the bin folder *.bat or *.sh file with min and max size of heap and all the jvm tuning properties only on the application server. 假设您已经启动了像oracle或jboss这样的应用程序服务器,它需要一个jvm实例,因为您已将jvm调整属性配置到bin文件夹* .bat或* .sh文件中,并且具有最小和最大堆大小以及所有jvm调整属性仅在应用程序服务器上。 while you deploy the multiple war file it is deployed on above the application server it takes java properties from the server. 当您部署多个war文件时,该文件部署在应用程序服务器上方,它将从服务器获取java属性。

But while you used the standalone application than in this case every application has configure in its own jvm properties. 但是,当您使用独立应用程序时,在这种情况下,每个应用程序都在其自己的jvm属性中进行了配置。

Concerning the class loader - it isolates (in theory) the server from the applications (EAR/WAR), and each application from each other. 关于类加载器-它在理论上将服务器与应用程序(EAR / WAR)隔离,并使每个应用程序彼此隔离。 For example, suppose the server uses Spring 3.x, and app 1 uses Spring 4.x. 例如,假设服务器使用Spring 3.x,而应用程序1使用Spring4.x。 The isolation allows the server to only see 3.x while app 1 can only see 4.x 通过隔离,服务器只能看到3.x,而应用程序1只能看到4.x。

But what happens if app 1 doesn't include the Spring 4.x jars in its EAR/WAR? 但是,如果应用程序1在其EAR / WAR中不包含Spring 4.x jar,会发生什么? The parent class loader (the server) attempts to load Spring which will of course be 3.x. 父类加载器(服务器)尝试加载Spring,当然应该是3.x。 Then any dependencies are also loaded from the server context. 然后,任何依赖关系也将从服务器上下文中加载。 This might actually appear to functionally work (scary), but more likely you end up with MethodNotFound and ClassNotFound exceptions. 这实际上似乎在功能上很有效(吓人),但您更有可能遇到MethodNotFound和ClassNotFound异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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