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 |
What is currentthread()?
What is inner class?what is the use of inner class?where we create the object for inner class? and inner class can extend any class or inner class can implement any interface?
what is Abstract DataType?
What is a parameter used for?
Why string is a class?
What is the difference between math floor and math round?
Can we use both this () and super () in a constructor?
what are the major differences between jdk1.4 and jdk1.5?
2 Answers Cap Gemini, Crimson Logic, Infosys, TCS, Tenth Planet,
Why are parameters used in functions?
How many types of threads are there in java?
What is final access modifier in java?
Difference between local and global transaction ?