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 the difference between superclass and subclass?

1174


What is a method in coding?

1054


What is the use of arraylist class in java?

1080


Is java free for commercial?

922


What is JFC?

1243


What are memory tables?

1096


Describe what happens when an object is created in java ?

1008


What is string made of?

957


What are variable names?

978


What is garbage collection? What is the process that is responsible for doing that in java?

1103


What are 3 data types?

994


What is palindrome in java?

991


Can we print null in java?

1060


how to create constants in java?

1083


What is a stack class in java ?

1104