Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9192055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:50:06+00:00 2026-06-17T20:50:06+00:00

Possible Duplicate: Java Synchronized Block for .class I was reading through an article on

  • 0

Possible Duplicate:
Java Synchronized Block for .class

I was reading through an article on synchronization. I am confused on below points and need more clarification

  1. For synchronization block. How

    synchronized (this) {
        // code
    }
    

    differs from

    synchronized (MyClass.class) {
        // code
    }
    
  2. Synchronizing instance method means threads will have to get exclusive lock on the instance, while synchronizing static method means thread will have to acquire a lock on whole class(correct me if I am wrong). So if a class has three methods and one of them is static synchronized then if a thread acquires lock on that method then that means it will acquire lock on the whole class. So does that mean the other two will also get locked and no other method will be able to access those two methods as the whole class is having lock?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:50:06+00:00Added an answer on June 17, 2026 at 8:50 pm

    MyClass.class and this are different things, they are different references to different objects.

    this – is a reference to this particular instance of the class, and

    MyClass.class – is a reference to the MyClass description object.

    These synchronization blocks differ in that the first will synchronize all threads that deal concretely with this instance of MyClass, and the second one will synchronize all threads independently of which object on which method was called.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Java Synchronization I'm reading the book Beginning Android Games . It uses
Possible Duplicate: Thread safety in Java class I'm reading Java concurrency in Practice ,
Possible Duplicate: Java: Always override equals? should I override equals function for any class
Possible Duplicate: Java inner class and static nested class What are the uses of
Possible Duplicate: Java Generics To be more specific, whats the role of the <String>
Possible Duplicate: java class declaration <T> Sometimes I've seen that java classes are created
Possible Duplicate: Efficient way to implement singleton pattern in Java I was reading this
Possible Duplicate: synchronized block vs synchronized method? From accepted answer to this question: In
Possible Duplicate: Java static class initialization Why is the string variable updated in the
Possible Duplicate: Java: Rationale of the Object class not being declared abstract Why is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.