Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

synchronization construct  RSS feed

 
neeti ravi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
i would like to know somethin' on this
What synchronization constructs does Java provide? How do they work?
can anyone help
thanks
neeti
 
Marcela Blei
Ranch Hand
Posts: 477
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
neeti: I don�t unsderstand the point of your question, could you please be more specific?
Thank you very much.
 
ANAND RAMKUMAR
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
neethi,for the reason the threads are not predictable java has imposed synchronized in the compile time itself by providing this as one of the access specifier..synchronization basically lock that instance of the object.if the method is syn...ed before it is invoked by an thread the methods aquires the lock of the object and because the lock is not available for the other syn...ed methods,it will not start executing..
 
Jignesh Malavia
Author
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is only one synchronization construct in Java and that is a lock/Monitor pair. A block(peice of code) or a set of blocks that need to be synchronized should be associated with a lock_object. Every thread that needs to execute that block (critical section) needs to acquire a monitor over the lock_object. Whoever gets the monitor on the lock executes. The others wait for it to release the lock.
You can
1) Acquire a lock/monitor on the whole Object
2) Acquire a lock on a part of the code within a method of the object
3) Acquire a lock/monitor on the Class (for static members)
Other than that there are no mutex/semaphores/...etc. kind of synchronization constructs. But the above takes care of almost all types of requirements.
Jigs
@(www.enthuware.com)
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2) Acquire a lock on a part of the code within a method of the object

Code does not have a lock which can be acquired. I guess you mean that aquire a lock on a specific object (it can be or not be the instance object which owns the code) to lock the code block.

Thanks!
Roseanne
Join our Study Group when certified
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!