wat is class level lock and object level lock
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
Explain public static void main(string args[]) in java.
Where can I find jdk in my computer?
Can set contain duplicates?
What is bubble sort in java?
How many types of assembly languages are there?
How do you change an int to a string?
How to call static method?
What is the benefit of using enum to declare a constant?
What is difference between final and immutable?
Is java is a fully object object oriented language?
What does the string method compareto () do?
why we are calling j2se why not j1se or j3se or j4se..etc is there any reason.. can u please explain it... i shocked in my interview when they asked this question please explain ans