synchronization - Confusion in working with monitors in java -
i'm trying understand how utilize monitor in java. far can tell, java doesn't provide monitor can create binary or counting semaphore. since case, mean when see people like:
while(!b){ x.wait(); } what x in case? class built mimics monitor action has wait() method?
why not this
while(!b){ wait(); } ? it can have multiple monitors? if so, why? seems @ point might utilize semaphore...
overall think issue understanding monitor , how utilize it. appreciate insight can give me.
wait() method of java.lang.object. every java object has instrinsic lock, called monitor.
x.wait() waits on object references variable x. wait() equivalent this.wait(), , waits on object referenced this.
that said, wait() low-level , hard utilize abstraction. you'd improve utilize higher-level abstraction, a... semaphore, java has. check out in javadoc.
also check out java's concurrency tutorial, covers these topics.
java synchronization
No comments:
Post a Comment