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
Give us the name of the list layoutmanagers in java?
Can java inner class be static?
can java object be locked down for exclusive use by a given thread? : Java thread
What is a double?
1.IN CASE OF DYNAMIC METHOD DISPATCH WHY WE USE REFERENCE VARIABLE,WE CAN USE THE DIFFERENT DEFINED OBJECT DIRECTLY TO ACCESS THE DATA MEMBER AND MEMBER FUNCTION OF THAT RESPECTIVE CLASS?WHAT IS THE MAIN FUNCTION OF "REFERENCE VARIABLE" HERE?
How can you add and remove nodes in jtree?
Which container method is used to cause a container to be laid out and redisplayed in java programming?
What is method overloading in JAVA? Why is it not present in C ?
What is passing by reference in java?
What is the disadvantage of synchronization?
What is the difference between iterator and list iterator?
What is the Difference between Final Class && Abstract Class?
Explain about static imports in java?
What is use of static in java?
What is collection sort in java?