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 a class reference?

1087


Write a java program to check if a number is prime or not?

1031


What is the locale class in java programming?

1070


What do you understand by java virtual machine?

1182


How does compareto work in java?

1030


Explain what is encapsulation?

1078


How do I remove a character from a string in java?

956


What does || mean in vectors?

928


What is a method header?

1011


Is object a data type?

954


Explain the differences between static and dynamic variables?

1137


Why put method is idempotent?

904


What does a za z0 9 mean?

1093


Which is better singleton or static class?

978


Where are the local variables stored?

1067