* Java multithreading is basically implemented through the Thread class and runnable interface.
* Thread class Method
* Constructor
Thread ();
Thread (runnable); // used together with the interface, mainly to help the interface implement the START () method, because the runnable interface does not have the start Method
Thread (string name); // thread name
Thread (runnable, string name); // 4 = 2 + 3
* Other Methods
Start (); // start the thread
Interrupt ();//
Join (); // call other threads
Run (); // thread body
Sleep (long time); // sets the thread sleep time.
Wait (long time); // = sleep (long time)
Wait ();
Y (); // activates the thread, which is generally used with wait ().
Policyall ();
Isalive (); // check the thread status
Stop (); // force the thread to die
* The runnable interface has only one run () method. Therefore, interfaces are generally used together with tread objects.
* Thread Lifecycle
Create; // put the statements that require multi-thread execution into the run method.
Executable; // when the thread enables the START () method, it enters the executable state and executes the run () method.
Non-executable; // you can use the wait () and sleep () methods in the tread class to enter the "non-executable state ".
Dying; // when the run method is executed, the thread automatically disappears.
* Thread priority
The setpriority () method in the Thread class can be used to set the thread priority. The value range is 1 ~ 10. The default value is 5.
* Daemon
If all non-Background threads are finished, the background threads will also be terminated automatically.
Thread. setdaemon (Boolean on); // when the parameter is true, the thread is marked as the background thread.
Thread. isdaemon (); // determines whether the thread is a background thread.