Why we use static and synchronized in method for single
thread model
example:
public static synchronized add(){}
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / sameer
Ststic means it belongs to class.When u call a syncronized
method u keep the luck of that class.
| Is This Answer Correct ? | 2 Yes | 4 No |
how and when compiler knows that the Java code throws the checked Exception.
What is the difference between the file and randomaccessfile classes?
What does main method?
Difference difference paint() and paintcomponent()?
What is the return type of a program?s main() method?
what are the design patterns in struts?
What are annotations in java?
Does unicode support all languages?
What is unicode used for?
What technique can be employed to compare two strings?
they asked class A{} class B{} class c{} all the three class saved as a single file,there is no main method in the file and anothe class M.java class m { psvm(String args[]) { // here the parent class can access } }
2 Answers DNS, IPSR Solutions,
Can java arraylist hold different types?