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
What is the difference between stringbuffer and stringbuilder?
What is java and why do we need it? Explain
Explain the concept of hashtables?
What is meant by call by reference?
How to sort an unsorted array in java?
What is the full meaning of java?
Is char a data type in java?
How many bits are in a sentence?
How do you define a parameter?
When is an object subject to garbage collection?
What is the set interface in java programming?
Which collection is best for sorting in java?
How to store image in arraylist in java?
What are the two parts of a conditional statement?
Is arraylist a class in java?