Recently in re-finishing learning Java multithreading. First, consider when you need to use multithreading.
Usually some asynchronous processing, background tasks, to maximize the use of resources such as Cpu,i/o,printer and so on. You can refer to the following
Http://www.cnblogs.com/kenshinobiy/p/4671314.html
Learn Tutorialspoint Java multithreaded programming after summarizing the following
Http://www.tutorialspoint.com/java/java_multithreading.htm
The first thing to know
Thread's life cycle and stage
Priority
Each thread has a priority. From 1 to 10. Normal is 5.
A thread that does not necessarily have a priority will be able to get resources. Priority only raises the probability.
Creation
There are generally two ways to create a thread. Implements the Runnable interface. or inherit the thread. The use of the executor framework is also mentioned below. No in-depth understanding of the framework.
Http://www.cnblogs.com/yezhenhan/archive/2012/01/09/2317636.html
Methods
The thread-specific method can refer to the JDK Reference
Http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html
It is particularly important to note that some methods are static, and some methods are instance methods. Others are inherited from object, such as Notirfy and wait. These are primarily used for thread communication.
Attention
The direct call run method is the same as when you call an object normally. But with start, a new thread will be started.
Yield is a concession.
Join, waiting for a certain amount of time for the thread to die.
The concept of daemon threads
Relative to the user thread. By means of Setdaemon you can make a thread a daemon thread. Typically, the daemon is responsible for managing the work of the thread, without accessing any resources, and finally exiting when there is no user thread. See below
Http://www.cnblogs.com/luochengor/archive/2011/08/11/2134818.html
Sychonization and Deadlock
In order to ensure the orderly access of resources, prevent the same resource from being confused by different threads, it is necessary to manage sychonization synchronously. is actually using locks. Also called Monitor. Usually the Sychonized keyword is used to specify a lock object. Then write the code in the block. You can also declare methods. But it is generally recommended in block form. Deadlocks are usually used because of the nesting of sychonized.
Reference
Http://www.tutorialspoint.com/java/java_thread_synchronization.htm
Http://www.tutorialspoint.com/java/java_thread_deadlock.htm
Thread Communication
Inter-thread communication. The main thing is the use of the Wait () and notify () methods. Wait causes the current thread to wait until there are other threads notify. Notify wakes up a thread that is currently locking the object.
Reference
Http://www.tutorialspoint.com/java/java_thread_communication.htm
Http://www.tutorialspoint.com/java/java_thread_control.htm
If you think you have a preliminary grasp of multithreading, you can look at the following questions, test whether you know it.
Http://www.cnblogs.com/kenshinobiy/p/4671302.html
Producer Consumer Model Producer-consumer pattern
When it comes to multithreading and concurrency, it is necessary to know the producer consumer model. This pattern mainly contains the following elements
1) A number of producer threads and consumer threads.
2) buffer. is usually a FIFO queue.
3) signal variable. Monitor whether the buffer is full or empty.
Reference
http://www.infoq.com/cn/articles/producers-and-consumers-mode/
https://software.intel.com/zh-cn/blogs/2014/09/17/java-0
http://cmsblogs.com/?p=1300
The last two links, one is the Concurrency guide for Oracle Java JDK. One is a series of articles from IBM.
Http://docs.oracle.com/javase/tutorial/essential/concurrency/index.html
https://www.ibm.com/developerworks/cn/java/j-concurrent/
Java multithreaded programming