Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Which intrinsic lock is acquired by a synchronized method in Java?

Pragya Keshap answered on February 4, 2023 Popularity 1/10 Helpfulness 8/10

Contents


More Related Answers

  • Difference between Lock Interface and synchronized keyword
  • Can we use primitive values for intrinsic locks?

  • Which intrinsic lock is acquired by a synchronized method in Java?

    1

    When we mark a method as synchronized and then call this method,

    then this method will first acquire the intrinsic lock of the object in

    which that method is mentioned.

    Once the synchronized method returns, it releases the lock.

    In case the synchronized method throws an exception, the intrinsic

    lock will be released.

    Sample code equivalent to a synchronized method is:

    public void myMethod() {

    synchronized(this) {

    }

    }

    https://www.logicbig.com/tutorials/core-java-tutorial/java-multi-threading/java-intrinsic-locks.html

    Popularity 1/10 Helpfulness 8/10 Language java
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on Feb 04 2023
    Pragya Keshap
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.