First solve the Java thread, solve the Java thread
Differences between threads and processes:
A process is essentially an execution program. Each process has its own code and data space. A process-based multitasking feature allows your computer to run two or more programs at the same time. For example, your computer can run other applications such as fetion while running QQ. In process-based multi-task processing, a program is the smallest unit of code assigned by the scheduler.
Thread-based is the sequential control flow within a program. It can be viewed as a lightweight process. The same thread shares code and data space. Simply put, you can use a cool dog to listen to music and search for your favorite songs.
Thread priority:
Java assigns priority to each thread to determine how to treat the thread when comparing it with other threads. The thread priority is used to determine when to switch from one running thread to another (that is, context conversion)
Conversion rules:
1. The thread can automatically discard the control. When I/O is not determined, sleep or congestion is accomplished with a clear concession. Under this assumption, all other threads are detected, and the highest priority thread to be run is granted the CPU.
2. Threads can be preemptible by high-priority threads. In this case, a low-priority thread does not take the initiative to give up, but the processor is occupied first-no matter what it is doing-the processor is occupied by a high-priority thread. Basically, once a high-priority thread needs to run, it will execute. This is called multi-task processing with priority.
Thread creation:
First: implement the Runnable interface
Second: Define Thead subclass to override its run Method
The first method is recommended when we do not need to overload other methods of Thead class. Because the Thread class defines multiple methods that can be reloaded by the derived class. The only method that must be overloaded is the run () method. This is exactly the same method required to implement the Runnable interface. Therefore, you only need to implement the interface when you do not need to reload other methods.
Thread control method:
Different from other languages, Java supports multiple threads. multithreading is often used in large and medium-sized software development in the future. With basic knowledge, you can write more code to deepen your understanding of this knowledge.