1. Multithreading Security issues
1) Synchronized keyword: How to lock the problem, choose the Synchronized method or synchnized code block.
Select which lock question, this object, or class object (for static method or variable), or object
It is recommended to use a synchronous code block, because the lock is flexible and you can choose which lock to use, especially if there are multiple synchronization methods in a class.
Read and write problems, to ensure that multithreading to the same object read and write normal, not to read dirty data. Read and Write methods share the same lock.
Shared resources, which in turn involve a single-mode thread-safety problem, a threads pool, and so on.
2) thread-safe classes, such as stringbuffer,cocurrenthahmap,hashtable,vector, etc.
3) threadlocal, another kind of thinking to achieve multi-threaded security issues, commonly used in the database connection pool, the connnection into the threadlocal, to ensure that each thread uses the same connection, and thus ensure that the transaction is unified.
Synchronized is the principle of sequential access through multithreading, sacrificing efficiency.
Threadlocal is the way in which the variables are copied into each thread's working memory by expanding the memory, and each thread space has a separate copy of the variable.
Java Multithreading Knowledge points Summary (four) multi-threaded knowledge point context diagram