Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


Can a lock be acquired on a class?

Answers were Sorted based on User's Feedback



Can a lock be acquired on a class?..

Answer / ravikiran(aptech mumbai)

yes indirectly because we can aquire a lock on the object of
the class.And for the class level lock we make use of static
synchromnized block.

Is This Answer Correct ?    8 Yes 2 No

Can a lock be acquired on a class?..

Answer / 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

Can a lock be acquired on a class?..

Answer / janet

Yes, a lock can be acquired on a class. This lock is
acquired on the class?s Class object.

Is This Answer Correct ?    4 Yes 0 No

Post New Answer



More Core Java Interview Questions

how to print hello world every second till i have pressed enter key ???

1 Answers   SAP Labs,


What does the three dot emoji mean?

0 Answers  


Can we use string in the switch case?

0 Answers  


How is a variable stored in memory?

0 Answers  


Is it possible to create Userdefined Unchecked Exception also?If Yes, give an example?

2 Answers   ADP,






What is the use of a conditional inclusion statement in Java ?

0 Answers   Global Logic,


Is minecraft 1.15 out?

0 Answers  


What is JFC?

0 Answers  


What is the difference between a constructor and a method?

0 Answers  


What are access specifiers in java ?

0 Answers   Akamai Technologies,


What is rmi and steps involved in developing an rmi object?

0 Answers  


Which of the following can be referenced by a variable? A. The instance variables of a class only B. The methods of a class only C. The instance variables and methods of a class

2 Answers  






Categories