wat is class level lock and object level lock

Answers were Sorted based on User's Feedback



wat is class level lock and object level lock..

Answer / ask

Class Lock - If a static method is marked as Synchrnozied
and called by a Thread, the whole Class will be locked
until the method execution completed.

Object Lock - If a non-static method is marked as
Synchronzied and called by a Thread, the current instance
(Object) will be locked util the method execution completed.

Is This Answer Correct ?    53 Yes 5 No

wat is class level lock and object level lock..

Answer / michael selvan

Class Lock - If a static method is marked as Synchrnozied
and called by a Thread, the whole Class will be locked
until the method execution completed.

Note : If we declare as a any static variables or methods
those will be stored in class area. So, if the method is
synchronized static . It'll lock the complete class.

Is This Answer Correct ?    4 Yes 0 No

wat is class level lock and object level lock..

Answer / sitaram

class StringSample{
static void method1(){
System.out.println("classlevel...");
}
void method2(){
System.out.println("object level...");
}

}
public class StringDemo{
public static void main(String[] args) {
StringSample.method1(); // class level
// StringSample.method2(); //error
StringSample s2 = new StringSample();
s2.method2(); //object level

}
}

Is This Answer Correct ?    8 Yes 18 No

Post New Answer

More Core Java Interview Questions

what is difference between front controller and action servlet?

2 Answers  


can anyone explain me the concept of autoboxing?

3 Answers  


Can we override protected method in java?

0 Answers  


What is the purpose of the File class?

3 Answers  


Hi, This is ravi i have a question like this i have string "UNDERSTAND" now i want to count the letters how many times it occures.i.e from the above string the out put should be like this U-1,N-2,D-2,E-1,R-1,S-1,T-1,A-1. how can i achieve this Thnaks in advance for your response ..

7 Answers  






How to optimize the javac output?

0 Answers  


What does sprintf mean?

0 Answers  


What is the USE of Null interfaces ??...if thers nothing inside these interfaces how are they used and WHy are they used ???? No 1 has given a proper description yet

1 Answers  


When do you create an index?

0 Answers  


Which method will get invoked first in a stand alone application?

1 Answers  


How we can execute any code even before main method?

0 Answers  


What is type inference in java8?

0 Answers  


Categories