DelphiFAQ Home Search:

Thread synchronization in Java


comments2 comments. Current rating: 5 stars (2 votes). Leave comments and/ or rate it.

Threads run in the same memory space and it is important that a thread does not inadvertently overwrite another's data. To control threads access to common data, Java offers the synchronized statement.

synchronized locks an object, preventing access to it, until it is unlocked.

When some other thread tries to access the locked object it remains blocked until the previous thread finishes and unlocks the object.

Locking and unlocking is done implicitely by Java. The programmer has only to use the synchronize statement:

  // obj has to be an object reference
  synchronized (obj) 

  // statements

Content-type: text/html


2008-01-23, 21:29:24 from India  
it doesn't give details about how java does locking and unlocking.
2008-06-23, 07:35:13
anonymous from Louisville, United States  



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: