Good programmers Java JVM share structure

  Good programmers Java JVM share structure, the basic structure jvm, that is, we called Overview. A lot of content, but also a great amount of concepts, on the concept of respect, let concepts into graphics in your mind, so long as you have the patience , careful , play their own imagination, it will make you full of faith heart . Of course, not to say that after reading it for jvm understand it , very much knowledge jvm learning. In your reading, we will follow to learn the details of jvm, but if you read down the premise of the study, to learn other details jvm will be more effective.

1. What is the java virtual machine

  First we write a class

Picture 1.png

Then open cmd window, type: java test.JVMForJava, open the Task Manager - the process, you see a program called java.exe no, yes, this is the java virtual machine, java xxx This command is used to start a java virtual machine, while the main function of the entrance is a java application, when the main function is executed, java virtual machine started. Well ctrl + c to end your jvm. Open your ecplise, right-run application, and then run application once again open the Task Manager - the process, well, we will see two javaw.exe, why are there two? Because we have just run twice run application. I am here to tell you, a java application corresponds to a java.exe / javaw.exe (java.exe and javaw.exe you can think of it as java virtual machine, there is a window interface without). You run several application there are several java.exe / javaw.exe. Or more specifically, you run several main function will start a few java applications, while also launched several java virtual machine.

  What is the java virtual machine and virtual machine instances? java virtual machine is equivalent to one of our java class, java virtual machine instances, we are quite a new class java, but java virtual machine but not to start a virtual machine by java.exe or javaw.exe by new keyword instance.

2, the JVM lifecycle

(1)  word does not say look at the code, and then after application in open Task Manager ecplise in run - the process, you will see a javaw.exe virtual machine running, view the console output, and observe the Task Manager javaw.exe have disappeared.

Picture 2.png

  (I will not result shots, and too long.)

  If you look at the console and Task Manager javaw.exe will find that when the main function for printing cycle finished, I want to program it with not the same as actually did not quit, but to wait until the entire new Thread () in the anonymous class after running the run method, javaw.exe only exit. We know that in win32 programming c ++'s (CreatThread ()), main function execution is over, boarding thread also pulled out, and in c # if you use the thread pool (ThreadPool), then the conclusion is true, threads are followed by the end of the hosting process and End. But in java looks like and our knowledge is very different, how this is going, do not look at the results of the first to think why.

  Yes this is due to the java virtual machine, it has two threads a Jiaojiao daemon threads, called non-daemon thread , main function is a non-daemon threads , virtual machines gc is a daemon thread . java virtual machine, as long as there is any non-daemon thread is not over yet, examples of java virtual machine will not quit, even if the main function of this non-daemon thread exits, but due to the start of the main function thread is anonymous non-daemon thread, it is not over, so no way jvm exit.

  Java virtual machine life-cycle, when a java application main function also start the virtual machine is started, and only when all non-daemon virtual machine instance is over, java virtual machine instances until the end of life.


Guess you like

Origin blog.51cto.com/14249543/2403276