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 the difference between throw and throws?

10 Answers   IBM,


what is business objects?

2 Answers  


What does yield method of the thread class do?

0 Answers  


Given a singly linked list, how will you print out its contents in the reverse order? Can you do it with consuming any extra space?

0 Answers   Akamai Technologies,


What does index mean in java?

0 Answers  






What does the three dot emoji mean?

0 Answers  


I have a sorting issue with a Hashmap. My constraint is that I MUST use the Hashmap and work with existing code. I do a database query and place the results in a Hashmap. When I iterate thru the Hashmap, it loses the original alphabetical sorting done by the database. So, my problem is that I must sort the results coming out of the Hashmap which is then placed into another class.

1 Answers  


Explain access modifiers in java.

0 Answers  


How do you call a reference in java?

0 Answers  


What is meant by Static query and Dynamic query?

2 Answers  


Hi Anyone know the model / questions of the Federal bank sample questions for the post of Specialist Officers - Programmers. Please post if anyone have..

0 Answers  


What are the supported platforms by java programming language?

0 Answers  


Categories