Answer Posted / jamshed katta
A lock can be acquired on a class, you would want to do that if you are using static methods in your class, in which case there would be only one copy, so you would need a lock on the class rather than the instance.
Eg:
public static int getPageHits{ // Not synchronized
return hits;
}
so, now instead of using
public static int getPageHits{
synchronized(this){
return hits;
}
}
you would rather do
public static int getPageHits{
synchronized(ClassName.class){
return hits;
}
}
where ClassName is the name of the class whose lock u are trying to acquire.
you could also use Class.forName("ClassName")
| Is This Answer Correct ? | 5 Yes | 0 No |
Post New Answer View All Answers
Explain the Propertie sof class?
What are the five major types of reference sources?
How can you read an integer value from the keyword when the application is runtime in java? example?
Can we declare a class as static?
What is covariant return type?
What is basic syntax?
Discuss about garbage collector in Java.
How do you remove duplicates in java?
What is the final access modifier in java?
What is module in oop?
What is the use of a copy constructor?
What do you mean by byte code?
Will the jvm load the package twice at runtime?
Why volatile is used in java?
What are the types of strings?