Let’s say I have a class Employee and I create the object of that class as
Employee emp = new Employee();
What is the difference between the below two synchronized blocks
synchronized(emp){ } and
synchronized(Employee.class)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
The first one uses one Employee instance as monitor. The second one uses the Employee class as monitor.
If the goal is to guard instance variables of an employee, the first one is makes much more sense than the second one. If the goal is to guard static variables of the Employee class, the second one makes sense, but not the first one.