Lock optimization for Java virtual machines

Source: Internet
Author: User

1 lock bias. When an object lock is requested out of the box, if the lock is acquired, the object lock enters bias mode, and when the thread requests the lock on the object again, no further synchronization is required.
You can turn on the bias lock by turning on the parameter-xx:+usebasedlock in the Java Virtual machine
The applicable environment is: The lock competition is not very intense. If the lock is in a very competitive environment, it is likely that the next time the current lock is not the same thread, the bias lock is invalid
2 Light weight lock. If the bias fails, the virtual machine does not immediately suspend the thread. The virtual opportunity simply takes the object's head as a pointer, pointing to the inside of the stack holding the lock, to determine whether a thread holds the object lock.
If the thread obtains a lightweight lock success, it can go inside the thread smoothly.
3 spin lock. If a lightweight lock fails, the thread is not immediately suspended, and the virtual machine makes a final effort: spin lock. Since other threads have acquired the lock, we do not know when the lock will be released, and if it is simply rude to suspend the current thread directly, it may outweigh the costs and increase the resource consumption. At this time the virtual opportunity assumes that in the near future we can get locks. The system causes the current thread to make several empty loops, and after several loops, if the lock is acquired, it enters the critical section or hangs the thread.
4 lock removal. When a virtual machine is JIT-compiled, it scans the context to remove locks that cannot compete with resources

Lock optimization for Java virtual machines

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.