A static method can be synchronized. If you do so, the JVM will obtain a lock on the java.lang.Class instance associated with the object. It is similar to saying: synchronized(XYZ.class) { }
Showing Answers 1 - 16 of 16 Answers
anupama
Jul 21st, 2005
why not!!! Static method can be synchronized.
nomaan khan
Aug 1st, 2005
Static methods can be synchronized. Synchronization has to deal with code which leads to deadlock or some uncertainity. The static methods can be accessed by diffrent threads. No problem in synchronization them
Srimant Misra
Aug 12th, 2005
A static method can be synchronized. If you do so, the JVM will obtain a lock on the java.lang.Class instance associated with the object. It is similar to saying: synchronized(XYZ.class) { }
Sisodiya Pramod
Aug 16th, 2005
Never, because synchronised is use for threads shareable data and thread is access data through object but static methods not called by object.
Yash Garg
Sep 11th, 2005
Yes a method can be specified as static as well as synchronized.
Example
class a
{
public
}
Yash Garg
Sep 11th, 2005
Yes a method can be specified as static as well as synchronized.
Example
class a
{
public static synchronized int function() {}
}
This is call class level synchronization.
Sunil Fotedar
Sep 12th, 2005
Each object has a lock associated with it. When any thread attempts to access a synchronized member, it must first acquire the associated objects lock. Once one thread owns the lock, no other thread may acquire the lock until the owning thread releases it which happens automatically when the synchronous operation completes. You can even make static members synchronized. Then the lock affects all objects of a given class, not just one particular instance.
Kshitish Pradhan
Oct 14th, 2005
Plz give the correct answer as we r referring.
varun paramala
Oct 14th, 2005
a method be static and synchronized . here the lock is acquired on the class it self instead of synchronized block(entire class will be under monitor)
SrinivasRao
Jan 17th, 2006
We Can give static and sychronized key words to a method
if u have any doubts
just run this program
u will know the truth
class Class2 { public Class2() {
} public static synchronized void aaa() { System.out.println("Example of staic synchronization of method"); } public static void main(String[] args) {
Class2.aaa();
} }
radhika
Jun 16th, 2006
yes it is working.
Niraj Lavankar
Mar 12th, 2007
No static method never be synchronized because static not realted with object,and deadlock condition occurs only when different object of the same class trying to acqire the same resources at a single instance.
Java Mamu
Jun 20th, 2007
Yes, As the case with normal synchronized methods Static methods can be synchronised. The only difference here is that to call that method a Thread needs to get the Class Lock, because static methods are class members.
Thanks Suhail
sadik
Jul 30th, 2007
hi please refer one more time static method's can be synchronized please go through the API u will find static synchronized method.
Can a method be static and synchronized
Editorial / Best Answer
Answered by: Srimant Misra
A static method can be synchronized. If you do so, the JVM will obtain a lock on the java.lang.Class instance associated with the object. It is similar to saying:
synchronized(XYZ.class)
{
}
Related Answered Questions
Related Open Questions