Is there one JVM per Java application?

Solution 1:

Generally speaking, each application will get its own JVM instance and its own OS-level process and each JVM instance is independent of each other.

There are some implementation details such as Class Data Sharing, where multiple JVM instances might share some data/memory but those have no user-visible effect to the applications (except for improved startup time, hopefully).

A common scenario however is a single application server (or "web server") such as Glassfish or Tomcat running multiple web applications. In this case, multiple web applications can share a JVM.

Solution 2:

There's one JVM per Java application. There shouldn't be any connection between them unless you establish one, e.g. with networking. If you're working inside of an IDE, the code you write generally runs in a separate JVM. The IDE will typically connect the separate JVM for debugging. If you're dealing with multiple web applications they could share the same JVM if they're deployed to the same web container.

Solution 3:

In theory you can run multiple applications in a JVM. In practice, they can interfere with each other in various ways. For example:

  • The JVM has one set of System.in/out/err, one default encoding, one default locale, one set of system properties, and so on. If one application changes these, it affects all applications.
  • Any application that calls System.exit() kills all applications.
  • If one application thread goes wild, and consumes too much CPU or memory it will affect the other applications too.

Solution 4:

Number of JVMs running is the number of executables invoked. Each such application invokes its own java executable (java.exe/ javaw.exe etx for windows) which means each is running in a separate JVM.