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

Is int primitive data type?

954


What is use of inner class in java?

1156


What is the access scope of protected access specifier?

1002


What is a package in java? List down various advantages of packages.

1279


What is an example of a keyword?

1110


What is the this keyword?

1035


What is continuity of a function?

1096


How does sublist works in java?

979


How to create a thread in java?

1144


What is the difference between dom and sax parser in java?

989


Does constructor be static?

1045


What is the multi-catch block in java?

1050


Can we override private method in java?

1095


Can finally block be used without a catch?

1014


Which is better stringbuilder or stringbuffer?

940