The difference between synchronized and lock in Java

Source: Internet
Author: User

The difference between synchronized and lock
Synchronize
The lock object can be any object, because the monitor method must have a lock object so that any object can be called by a method so that it is extracted into the object class to define the Monitor method
So that the lock object and the monitor object are the same, as long as the lock object is created it is both a lock object and a monitor object so that it cannot be implemented to bind multiple monitor objects on a lock object
The lock object in jdk1.5 is just a lock object
The monitor method is encapsulated in the condition object so that the lock object and the monitor object are detached more object-oriented
This enables multiple monitor objects to be bound on a lock object

Binding multiple monitor objects on a lock object solves the problem of one side waiting to wake the other in multi-producer multi-consumer multithreaded models

The difference between synchronized and lock in Java

Related Article

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.