Implement the Runnable interface:
Question 1: Is the object of the Runnable implementation Class A thread object?
A: no , the object is just an object that implements the Runnable interface, and only the child of thread or thread is the thread object.
Question 2: Why should the object of the Runnable implementation class be the most, the arguments passed to the thread object? What is the role?
A: The Run method of the object of the Runnable implementation class is executed as the thread's task code.
ImportJava.util.Scanner; Public classEX10 { Public Static voidMain (string[] args) {MyThread Mt=NewMyThread (); Thread Thread=NewThread (MT, "Dog Doll")); Thread.Start (); for(inti = 0; I < 100; i++) {System.out.println (Thread.CurrentThread (). GetName ()+ ": " +i); } }}classMyThreadImplementsrunnable{@Override Public voidrun () { for(inti = 0; I < 100; i++) {System.out.println (Thread.CurrentThread (). GetName ()+ ": " +i); } }}
Java Multi-Threading 5 (creation mode)