Java Virtual Machine Definition
Java virtual machines are called "virtual" because they are just abstract computers defined by a specification.
What is a Java Virtual Machine?
- Abstract Specification
- A specific implementation based on abstract specifications
- A running Virtual Machine instance
Java Virtual Machine abstract specification is just a concept. Generally speaking, Java virtual machines are specific implementations of this specification. This implementation may come from multiple providers and coexist on multiple platforms. It can be fully implemented by software, or by combining hardware and software. When a JavaProgramAt the same time, a Java Virtual Machine instance is running.
Java Virtual Machine (JVM) is an imaginary machine that is simulated by software. Java virtual machines have their own hardware, such as processors, stacks, registers (simulated by java stack), and corresponding command systems.
The Java Virtual Machine acts as a hardware platform. If it is equivalent to a real hardware system, the Java language is equivalentC LanguageThe compiled class bytecode file in Java is equivalent to the Assembly command for this hardware platform.
Lifecycle of a Java Virtual Machine
1: A running Java VM instance is responsible for running a Java program. When a Java program is started, a virtual machine instance is born. When the program is closed and exited, the virtual machine instance will die. If you run three Java programs on one computer at the same time, you will get three Java Virtual Machine instances. Each Java program runs in its own Java Virtual Machine instance
2: There are two threads in the Java Virtual Machine: the daemon thread and the non-daemon thread. Daemon threads are generally used by virtual machines, such as threads that execute garbage collection tasks. However, a Java program can mark any thread it creates as a daemon thread. The main thread of the main () method of the initial thread in the Java program is a non-daemon thread. As long as there are any non-daemon threads running, the Java program continues to run. When all the non-daemon threads in the program are terminated, the VM instance automatically exits. If the security manager permits, the program itself can exit by calling the exit () method of the runtime class or system class.