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
Does sprintf allocate memory?
What is composition in java?
Explain restrictions on using enum?
Is null or empty java?
How do you compare objects in java?
How do you check whether the list is empty or not in java?
How many types of equations are there?
How many digits can a float hold?
What does java se mean?
What about member inner classes?
What are design patterns and please explain?
What is the destroy method?
What is the difference between static class and normal class?
What is a method in java?
What is type conversion in java?