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?

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


Please Help Members By Posting Answers For Below Questions

Explain the Propertie sof class?

1113


What are the five major types of reference sources?

1210


How can you read an integer value from the keyword when the application is runtime in java? example?

1202


Can we declare a class as static?

1150


What is covariant return type?

1162


What is basic syntax?

1114


Discuss about garbage collector in Java.

1131


How do you remove duplicates in java?

1075


What is the final access modifier in java?

1123


What is module in oop?

1079


What is the use of a copy constructor?

1043


What do you mean by byte code?

1054


Will the jvm load the package twice at runtime?

1154


Why volatile is used in java?

1150


What are the types of strings?

1096