Process: A program that is in progress (literal translation). Thread: A control unit (execution path) in the process that is responsible for executing the program. A process can execute multiple paths, called multithreading.
There must be at least one thread in a process.
Multiple threads are opened to run multi-part code at the same time.
Each thread has its own running content. This content can be called a task that the thread will perform.
Multithreading Benefits: Solves the problem of multiple parts running at the same time.
The disadvantage of multithreading: too many threads back to the reduction of efficiency.
In fact, the implementation of the application is the CPU is doing a quick switch to complete. This switch is random.
When the JVM starts, it starts multiple threads, and at least two threads can parse it out.
1, the thread that executes the main function, the thread's task code is defined in the main function.
2, the thread responsible for garbage collection.
Class Demo extends Object{public void Finalize () {System.out.println ("demo OK");}} Class threaddemo{public static void Main (string[] args) {new demo (); new demo (); new demo (); System.GC (); System.out.println ("Hello world!");}}
A preliminary understanding of multithreading in Java