The
first kind: Inherit the thread class subclass to overwrite the Run method of the parent class, and write the threading code in Run (). A subclass object is created, and the thread is also built. Start the thread by using the Start method. The second is to implement the Run method of the
Runnable interface Subclass Overlay interface and write the thread code in run (). Creates a thread from the thread class and passes the subclass object implementing the Runnable interface as a parameter to the constructor of the thread class. The thread object calls the Start method to start the threads. The comparison between the two: inherit the thread class, relatively simple, but because of the limitations of single inheritance, the same resources are not shared, but not recommended to use, and implement the Runnable interface, multiple threads share a resource, the class can inherit other classes, implement multiple interfaces, so it is recommended to use.
Two ways to create a thread