1. A thread is an execution path in a process. The process is running in the system.Program. (Inbound and outbound is a static concept, while a thread is a dynamic concept .)
2. How to start a new thread:
A. inherit the Thread class and override the run method in the thread.
B. Implement the runnable interface.
Note: To enable a new thread, you call the start method, but directly calling the run method is only a common method call.
3. thread state conversion:
4. Basic thread control methods
Isalive () determines whether the thread is still "alive", that is, whether the thread has not been terminated.
Getpriority () obtains the priority value of the thread.
Setpriority () sets the priority value of the thread.
For details about thread. Sleep (), see the specified number of milliseconds for the current thread to sleep.
Join () calls the method of a thread and merges the current thread with the thread. That is, it waits until the end of the thread and then returns to the running of the current thread.
Yield () gets out of the CPU, and the current thread enters the ready queue for scheduling. (Only once)
Wait () but its thread enters the wait pool of the object.
Y ()/notifyall () Wake up one/all waiting threads in the waitpool of the object.
Note: The thread priority ranges from 1 to 10. The default value is 5.
5. Thread Synchronization aims to prevent data corruption when multiple threads access the same data object.
Method for implementing thread synchronization:
A,CodeBlock lock:
Synchronized (this ){......}
B. Method lock:
Public synchronised voidxxx (...){......}
6. Thread deadlock: a rare and difficult-to-Debug error occurs when two thread objects have circular dependencies on two synchronization objects.