Tenth chapter to avoid the danger of being active
Lock sequence Deadlock: Defines the order of the locks, which can be used to determine the order of each lock, such as hashcode or serial number.
In the case where the lock's call order is not obvious, calling other external methods in the case of holding the lock is important to note that you can avoid the danger of deadlocks by opening calls, that is, using synchronous block protection to protect only those shared variables, but this method of reducing the granularity of the lock may cause the original large code block to lose its atomicity. The workaround is to change the status of the service to hold the lock until it is closed, and the other thread will be able to see the shutdown information so that it does not perform the close operation again ...
Deadlock diagnosis and avoidance: Set timers through Trylock to avoid deadlocks, analyze deadlocks through thread dump information, and multiple threads not able to use the same JDBC connection at the same time
Hunger and slow response, live lock
Ways to avoid a live lock: introducing randomness into the retry mechanism
The 11th chapter performance and can extend the straight-tempered
Performance metrics: Speed of operation, processing power
How to evaluate? How to weigh?
Amdahl Law
Cost of thread Ingestion: Context switch, memory synchronization,
Modern JVMs can automatically optimize lock and memory reordering
Reduce lock contention: Reduce lock hold time, reduce lock request frequency, use exclusive lock with protocol mechanism
1. Fast-in fast-out
2. Decomposition of multiple variables protected by a lock into a single variable protected by multiple locks
Segment lock on a set of independent objects
3, using concurrent containers instead of exclusive locks, such as read-write locks, immutable objects, atomic variables
Don't use object pooling easily
Reduce context switching overhead
Java concurrency Programming the third part of the practical learning Note: activity, performance, and testing