Process: A program that is in progress. In fact, a process is a memory allocation space when an application runs. Thread: It is actually a program execution control unit in the process, an execution path. The process is responsible for the application's spatial labeling. Threads are responsible for the order in which the application executes.
A process has at least one thread running, and when multiple threads appear in a process, the application is called a multithreaded application, and each thread has its own execution space, its own method area, and its own variables in the stack area. When the JVM starts, it first has a main thread, which is responsible for the execution of the program, and the main function is called. The code executed by the main thread is in the main method. When garbage is generated, the garbage collection action is not required to complete the main thread, because in this case, the code execution in the main thread will stop, will run the garbage collector code, inefficient, so a separate thread responsible for garbage collection.
The principle of randomness: because of the rapid switchover of the CPU, which thread gets the execution of the CPU and which thread executes it.
Returns the name of the current thread: Thread.CurrentThread (). The name of the GetName () thread is defined by the: thread-number. Numbering starts from 0. The code that the thread wants to run is stored uniformly in the Run method.
The thread must be run by using the method specified in the class. Start method. (after startup, one more execution path) Start method: 1), start the thread, 2), let the JVM call the Run method.
The first way to create a thread is to inherit the thread, which is a subclass of the Run method. Step: 1, define the class inherits the thread class, 2, the purpose is to replicate the Run method, the code that will let the thread run is stored in the Run method, 3, by creating a subclass object of the thread class, creating a Thread object, 4, invoking the thread's Start method, opening the thread, and executing the Run method.
Thread state: Created: Start () Run: Qualified to execute, with execution right; Freeze: Sleep (time), wait ()-notify (), thread releases execution, release execution eligibility, temporary blocking status: Thread has CPU execution qualification, No CPU execution; extinction: Stop ()
My understanding of threading the Dark Horse programmer