First, the Synchronization container class1. Issues with the synchronization container classThread container classes are thread-safe. However, it is necessary to protect the safety of an additional lock when it is carried out in accordance with the operation.
Common compliance actions include:
. Iterations. Jumps (finds the next element of the current element in the specified order). Conditional operations
Iterative issues to view previous articles, "Java concurrentmodificationexception exception analysis and Resolution"
Second, concurrent containers
Collection type |
Non-thread safe |
Thread Safety |
List |
ArrayList |
Copyonwritearraylist |
Set |
SortedSet |
Concurrentskiplistset |
Map |
HashMap, SortedMap |
Concurrenthashmap, Concurrentskiplistmap, |
Concurrenthashmapcopyonwritearraylist
Third, block queue-producer consumer mode queue-Blockingqueue
Iv. blockage method and interruption method
the following excerpt from "Win Shaojin-Java Concurrent Programming Tutorial-"
The first way thread thread = new Thread ("Interrupt test") {public void run () {for (;;) { doxxx (); if (thread.interrupted ()) {Break ;}}} ; Thread.Start ();///Another way thread thread = new Thread ("Interrupt test") {public void run () {for (;;) { try { doxxx (); } catch (Interruptedexception e) {break ; } catch (Exception e) { // Handle Exception } } }};thread.start ();//Third Way public void Foo () throws interruptedexception { if (Thread.interrupted ()) { throw new interruptedexception (); }}
The program should respond appropriately to thread interrupts.
Five, the Synchronization tool Class 1. Latching CountDownLatch2. FutureTask3. Signal Volume 4. Fence (Barrier)
Vi. building an efficient and scalable results cache
Java concurrent programming in the fifth chapter of synchronization container class reading notes