Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

What is the use of static keyword in "public static void main()"

10 Answers   College School Exams Tests, Infosys, Six Dee Telecom,


can anyone explain me the concept of autoboxing?

3 Answers  


What is a parameter in java?

0 Answers  


what are the rules to use try catch finally?

1 Answers   Satyam, UJ,


Discuss 2D arrays.

0 Answers   Amdocs,


What is the difference between the reader/writer class hierarchy and the inputstream/outputstream class hierarchy in java programming?

0 Answers  


Are variables stored in ram?

0 Answers  


What are Brief Access Specifiers and Types of Access Specifiers?

1 Answers  


Program to print 1 1 2 1 2 3 1 2 3 4 like that

8 Answers   Huawei,


If you are reviewing the code of your team members, what points will you look at, assuming the performance of the application is not so great

2 Answers   KPIT,


what is difference Between Core Java and advance java

60 Answers   HCL, HP, Sambalpur University, TCS, Vensai Technologies, Wipro,


what is the Arraylist limit (maximum) by default ?

13 Answers   Fidelity, PlanetSoft, Wipro,


Categories