First, multi-threaded writing steps
1. Threading class Inherits Thread
2. Overriding the Run () method in a thread class
3. Create a thread object in the test class and start the thread with the start () method
How to Runnable interfaces
1. Thread class inheritance
2. Create a Thread object: Assuming that the thread class is runnable, use runnable myrunnable = new Myrunnable (), create the object, and then use the thread t = new thread (myrunnable);
3. Start the thread
Note: This method must create an object
The difference between a thread object calling start (), a method, and calling the run () method
1.run () only the main thread one execution path
2.start (): Multiple execution paths, the main thread and child threads are alternately executed in parallel
Methods for anonymous inner classes: Override the Run method directly in the test class
New Thread () { @Override publicvoid run () { // TODO auto-generated method Stubwhile (! Teemo.isdead ()) { gareen.attack (Teemo);}} ; T1.start ();
Some common methods of threading
Priority is 1~10, 1 lowest, default priority is 5
Synchronization method:
java--Multithreading