Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: RMI exceptions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RMI exceptions



On Sunday, July 4, 2004, at 08:47 PM, Eduard de Jong wrote:

just my 0.02$

Looking at the code with no further context,it seems that the
semaphore you are using is the size of the event queue.

Thats the initial loop.
psuedo-code would be...

DOLOOP: WHILE STUFF TO DO
DO IT
END WHILE
WAIT UNTIL MORE STUFF
GO TO DOLOOP

Almost Basic, reverting to high school.
But the DOLOOP is the only dependent on the ovents queue.
wait()
is the same as...
this.wait();
meaning 'this' is the object serialized on. Not the ovents queue or it's size.
The Object 'enclosing' the thread, the 'this', is actually a Runnable and not a Thread subclass, it _is not_ even the thread but a unique object in it's own right with it's own lock to serve as the semaphore.
I thought maybe thats whats different. Usually I do just subclass Thread but I don't see how that matters either.

Then, in my view, the code should synchronize on access to the
semaphore proper, not an object that encloses it.
Like this:
...
while(!stopped) {
synchronized (oevents) {
while(oevents.getSize() > 0) {
oevents.pop();
...
}//while work to do
try {oevents.wait();} catch { ... }
}//exclusive access to semaphore
...
}

Using the queue for synchronization would of been another way to go although I'm not necessarily seeing how it's more valid or superior although it might force the problem Greg was talking about where the queue being synchronized here prevents it's concurrent update elsewhere?


BTW
I just read William Grosso's "Java RMI" which explains amongst other
things the bug you experienced and has lots of hints on how to design
RMI applications, including the proper use of threads and thread-safe
coding.

Hopefully somebody has something somewhat like this working somewhere. I'll keep that in mind if I run into the book. I wouldn't complain by any means to have another decent source of information.


Mike Hall <mikehall at spacestar dot net>
<http://www.spacestar.net/users/mikehall>
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Re: RMI exceptions (From: Eduard de Jong <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.