Multithreading summary, the nine knowledge!

 


Learning multi-thread basis, this one enough friends! (A): https://blog.csdn.net/weixin_43827227/article/details/96606212

Learning multi-thread basis, this one enough friends! (B): https://blog.csdn.net/weixin_43827227/article/details/96982701

Multithreading Summary:

1, the concept of processes and threads.
       | - Process:

       | - Thread:

 

2, multithreading jvm is reflected.
       | - the main thread, the thread garbage collection, custom threads. And the position of the code they run.

 

3, when using multi-threaded, multi-threaded What good is that? Created to thread?
       | - When the need for multi-part code is executed at the same time, it can be used.

 

4, two ways to create threads. ★★★★★
       | - inherited Thread

              | - Step

       | - implement Runnable

              | - Step

       | - the difference between the two approaches?

 

5, 5 state of the thread.
       For the execution and implementation of the right qualifications specific features in the state.

       | - were created:

       | - run:

       | - Freeze:

       | - temporarily blocked:

       | - demise:

 

6, security threads. ★★★★★
       | - safety reasons:

       | - solving ideas:

       | - resolved reflect: synchronized

       | - synchronized premise: but with synchronization also security problems, we need to think in the premise.

       | - synchronization methods and the difference between two forms:

       | - Synchronization of the benefits and drawbacks:

       | - lazy single example.

       | - deadlock.

      

 

7, communication between threads. Wait / wakeup mechanism.
       | - concept: multiple threads of different tasks, deal with the same resources.

       | - wait wake-up mechanism. Use a locked wait notify notifyAll. ★★★★★

       | - questions producer / consumers. And more than production and consumption issues and more. while determination flag. Wake-up each other with notifyAll. ★★★★★

       | After --JDK1.5 appeared better solution, ★★★

              Lock the interface replaces the synchronized 

              Condition Object Interface alternative method of monitoring, the monitor and packaged in a method of Condition

              And the difference is previously set a lock can have a monitor method. Now, a Lock can lock multiple sets of monitor method of the object.

              You can implement a responsible producer, a group of responsible consumers.

       The difference --wait and sleep |. ★★★★★

 

      

 

8, stop the thread way.
       | - Principle:

       | - Performance: - interrupt.

 

9, the common thread of some methods.
       | --setDaemon () daemon threads

       |--join();

       | - priority

       |--yield();

       | - in the development, you can use anonymous inner classes to complete the partial path open.

 

Published 38 original articles · won praise 6 · views 1927

Guess you like

Origin blog.csdn.net/weixin_43827227/article/details/97006119