I. Java Multithreading Mode 2: Implementing the Runnable Interface
Benefit: A. Can avoid limitations due to Java single inheritance.
B. Suitable for multiple same program code to deal with the same resource situation, the thread and program code, data effectively separated, better reflect the object-oriented thinking. (e.g. multi-window ticketing)
1. Steps:
A. Custom class implementation interfaces
B. Overriding the Run () method
C. Creating the class instance
D. Create an object of the thread class, passing in the object created by C as a construction parameter
Note: The way to implement the Runnable interface cannot use the thread class method, which can be used indirectly. such as get the name of the thread: Thread.CurrentThread (). GetName ()
E. Starting a Thread object
2. Comparison of two different ways
3. Ticketing examples
See the next article.
Java Multithreading (two)