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

What is an interface in java?

1017


Define how can we find the actual size of an object on the heap?

1138


What are different type of exceptions in java?

935


What is this keyword in java?

1001


What is final keyword?

1105


What is static variable with example?

966


What if I write static public void instead of public static void in java?

1053


Is vector ordered in java?

969


What is multi-catch block in java?

1037


What is return type in java?

1020


Hi.... I applied for the post of scientific officer/Engineer-SB(Programmer).Please post the syllabus and sample papers.

1962


Can we declare a class as static?

1056


What are different types of inner classes ?

1016


Explain hashset and its features?

1103


What class of exceptions are generated by the java run-time system?

1139