How Java threads are created:
1. inherit the thread class to create a threading class
Inherit the thread class and override the Run method of the class, which represents the task that the thread will complete.
2. Creating thread classes through the Runnable interface
Implement the Runnable interface, overriding the run () method of the interface, and the method body of the run () method is also the thread execution body of the thread. Create a thread object with the Runnable implementation class instance as the target of the thread, which is the true thread object.
3. Create threads through callable and future
(1) Implement the callable interface, overriding the call () method, which will act as the thread execution body and have a return value.
(2) Use the Futuretask class to wrap the callable object.
(3) Use the Futuretask object as the target of the thread object to create and start a new thread.
(4) Call the Get () method of the Futuretask object to get the return value after the child thread execution ends.
Java thread pool:
Newsinglethreadexecutor
Newfixedthreadpool
Newcachedthreadpool
Newscheduledthreadpool
The Java thread pool is actually a producer and consumer model
Simple summary of JAVA threads and thread pools