Java concurrency Programming the third part of the practical learning Note: activity, performance, and testing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.