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, 2169👍, 0💬
Popular Posts:
How could Java classes direct program messages to the system console, but error messages, say to a f...
How To Remove the Top White Space of Your Web Page? - CSS Tutorials - Introduction To CSS Basics The...
What is the method to customize columns in DataGrid? Use the template column.
How To Create an Add-to-NewsGator Button on Your Website? - RSS FAQs - Adding Your Feeds to RSS News...
How To Control Padding Spaces within a Table Cell? - XHTML 1.0 Tutorials - Understanding Tables and ...