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
How do you start a new line in java?
Can a class have multiple subclasses?
What is Classloader in Java?
What is the r character?
How can you say java is object oriented?
What is the meaning of 3 dots in java?
If try block is successfully executed, Then Is Finally block executed?
What are the features of junit?
Is list ordered in java?
Difference difference paint() and paintcomponent()?
what do you understand by synchronization? Or what is synchronization and why is it important? Or describe synchronization in respect to multithreading? Or what is synchronization? : Java thread
Can we access the non-final local variable, inside the local inner class?
What are 5 boolean operators?
Where can i get Latest SUN Certification Dumps and what are the Sun Certification Codes that are available, Im new to JAVA, so please gimme info as i need to write J2EE - Core Java Certification
What is the difference between multiple processes and multiple threads?