Java 运行时如何映射到目标
根据运行时 Javadocs 此处:
每个Java应用程序都有一个Runtime类的单个实例,它允许应用程序与应用程序运行的环境进行交互。可以通过 getRuntime 方法获取当前运行时间。 应用程序无法创建自己的此类实例。
我的问题是:他们对应用程序的定义是什么?
每个 JAR/WAR/EAR 是否被视为独立应用程序?带有 main()
方法的普通 ole'Driver.class 类怎么样?容纳 EAR 和 EJB 的 Java EE 容器怎么样?
我想我正在尝试了解在复杂的(Java EE)系统中可以启动并运行多少个运行时实例。理解这一点需要我理解 Java 术语中哪些具体的“事物”构成了“应用程序”。
According to the Javadocs for Runtime here:
Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from the getRuntime method. An application cannot create its own instance of this class.
My question is: what's their definition of an application?
Is each JAR/WAR/EAR considered a standalone application? What about a plain ole' Driver.class
class with a main()
method? What about Java EE containers that house EARs and EJBs?
I guess I'm trying to understand how many Runtime
instances could be up and running inside a complex (Java EE) system. And understanding that requires me to understand what specific "things" constitute an "application" in Java terminology.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简而言之,每个 Java 虚拟机执行一个
Runtime
类的实例。方法:
Runtime
类利用 Singleton 设计模式来控制JVM运行期间的实例数量。请注意,该类没有公开可用的构造函数,因此获取实例的唯一方法是使用静态Runtime.getRuntime()
方法。此方法将始终返回相同的实例。原因:此类对 JVM 的运行时进行建模,因此它是一种准确的表示,可将每次 JVM 执行的实例数量限制为一个。
Simply put, one instance of the
Runtime
class per Java Virtual Machine execution.How: The
Runtime
class makes use of the Singleton design pattern to control the number of instances during the running of the JVM. Note the class has no publicly available constructor so the only way to obtain an instance is by using the staticRuntime.getRuntime()
method. This method will always return the same instance.Why: This class models the runtime of the JVM so it is an accurate representation to limit the number of instances to one per JVM execution.
应用程序是一组具有入口点
main
的类,这些入口点由命令java -cp THECLASSPATH Main
执行。简单的 HelloWorld 是一个应用程序,也是整个 Java EE 应用程序服务器以及部署在其上的所有组件、插件、适配器、Java EE 应用程序等也是应用程序。
Application is the bunch of classes that has entry point
main
that was executed by commandjava -cp THECLASSPATH Main
.Simple HelloWorld is a application as well as whole Java EE application server together with all components, plugins, adapters, Java EE applications deployed on it etc is application too.