Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How is static Synchronization different form non-static synchronization?
How is static Synchronization different form non-static synchronization?
✍: Guest
When Synchronization is applied on a static Member or a static block, the lock is performed on the Class and not on the Object, while in the case of a Non-static block/member, lock is applied on the Object and not on class. [Trail 2: There is a class called Class in Java whose object is associated with the object(s) of your class. All the static members declared in your class will have reference in this class(Class). As long as your class exists in memory this object of Class is also present. Thats how even if you create multiple objects of your class only one Class object is present and all your objects are linked to this Class object. Even though one of your object is GCed after some time, this object of Class is not GCed untill all the objects associated with it are GCed.
This means that when ever you call a "static synchronized" block, JVM locks access to this Class object and not any of your objects. Your client can till access the non-static members of your objects.
2013-03-19, 2134👍, 0💬
Popular Posts:
How To Export Your Connection Information to a File? - Oracle DBA FAQ - Introduction to Oracle SQL D...
Do You Know the Book "JUnit in Action"? You should know this book. It received some good reviews. Ti...
Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written...
What is NullPointerException and how to handle it? When an object is not initialized, the default va...
How To Divide Query Output into Groups? - MySQL FAQs - SQL SELECT Query Statements with GROUP BY You...