Process: Multiple task processes for the operating system, one system. For example, open a video play, open a QQ
Thread: is the running unit in the process.
Multithreading: A project or application can be executed in parallel by multiple threads and called by the CPU to allocate the time slices.
The state of the thread
1. Create New status New Thread ()
2. Ready state Start ()
3. Running state run
4. Blocking state loss of CPU time slices
5. Method execution is completed in thread termination thread
How threads are Created
1. Inherit thread override run method, disadvantage single inheritance, no longer inherit other classes
2. Implementing the Runnable Interface (static proxy) Benefits: You can inherit or implement other interfaces
3. Advantages of implementing Callable Interface: Can return a value, can throw a custom exception
Merge threads, queue up
Join ()
Pausing a thread
Yield () static method, pause the next one, not absolute, and then whether or not the pause depends on the CPU
Sleep () static method, not release lock, typically used for analog delay, countdown
Multithreading concurrent execution, Java can guarantee that each thread executes, does not guarantee the execution order
Thread priority: 1-10 higher priority gets CPU time slice more chances, not absolute
SetPriority (1)
Processes and Threads