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.
Simply put, one instance of the
Runtimeclass per Java Virtual Machine execution.How: The
Runtimeclass 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.