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
Why unicode is important?
What is style and indentation?
What is use of a abstract variable?
What are the advantages of java inner classes?
Explain the reason behind ending a program with a system.exit(0)?
Explain when noclassdeffounderror will be raised ?
What is the maximum size of array in java?
What does escaping a character mean?
What is your platform?s default character encoding and how to know this?
I have multiple constructors defined in a class. Is it possible to call a constructor from another constructor’s body?
What is initial size of arraylist in java?
Why we go for collections in java?
What is a void method?
Does isempty check for null?
What is continuity of a function?