Multithreading method created
- Thread class inheritance
- Implement Runnable (recommended)
- Callable implement interface (not used, JUC programming)
// use Runnable interface, you need to create the proxy object to call Thread Star () method; for example: TestThread implement Runnable, when calling: . 1 , TH = TestThread new new TestThread (); 2 , T = Thread new new Thread (TH) ; // proxy object 3 , t.star ();
Lambda
Using a Lambda simplified threads (for: using one method, and simple thread)
// the name of the inner class new new Thread ( new new the Runnable () { public void RUN () { . SYSOUT OUT .println ( " I'm a thread " ); } }).star();
Lambda simplify use:
// jdk8 added simplified lamdba new new Thread (() -> { public void RUN () { . SYSOUT OUT .println ( " I'm a thread " ); } }).star();
State of the thread
- Newborn state (new)
- Ready state (star)
- Operating status (CPU running)
- Blocking state
- Death state (external interference, normal thread is finished)