1. Inherit the thread class, overload the Run method
2. Implementing the Runnable interface, overloading the Run method
3. Use callable, with the future, and Executorservice to achieve multi-threaded return results
The first two methods are non-return values, the essence of the thread class is also implemented Runnable interface, representing a thread of the instance, through the thread class's start instance method (is the native method), will create a new thread, and execute the thread of the Run method
The way to implement the Runnable interface is more flexible, and if the class has inherited another class, it can only be implemented by inheriting runnable.
JDK1.5 introduced a new callable with return value, supporting the Executorservice thread pool interface and the future to use, can achieve a multi-threaded return value, Executorservice interface provides a Submit method, passing a callable or R Unnable, return to the future, if the executor background thread pool has no computed callable, then the call to the future object get () method will block to the completion of the calculation
3 Ways to implement multithreading