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...

Why we use static and synchronized in method for single
thread model
example:
public static synchronized add(){}

Answer Posted / deepak verma

Synchronized static method means, the lock belongs to the
class, no other thread can access any static synchronized
method of this class when one thread already holds the lock
of that class.

This class lock is independent of locks on its object. For eg :

Class A {
public static synchronized add() {}

public synchronized void someMethod() {}
}

Here add() and someMethod() can be called concurrently as
add() is having class lock whereas someMethod() having
object lock.

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Compare java and python.

935


Why is string buffer better than string ?

1039


Define an enumeration?

979


How to change value in arraylist java?

1096


What are the 3 types of loops in java?

987


Write an algorithm for quick sort?

967


What is flag in java?

926


Explain about main thread in java?

1037


How to do encapsulation in java?

997


Why can't we use static class instead of singleton?

885


What are some characteristics of interference class?

945


Explain about data types?

1000


What is the use of flag?

1020


How destructors are defined in java?

1121


What is a nonetype?

1047