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
Joined: Jun 28, 2000
Posts: 477
posted
0
neeti: I don�t unsderstand the point of your question, could you please be more specific? Thank you very much.
ANAND RAMKUMAR
Greenhorn
Joined: Jan 01, 2001
Posts: 8
posted
0
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
Joined: May 18, 2001
Posts: 81
posted
0
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
Joined: Nov 14, 2000
Posts: 1953
posted
0
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