Why should most logic be in the monitor objects and not in the thread objects when writing concurrent software in Java?

Posted by refuser on Programmers See other posts from Programmers or by refuser
Published on 2012-11-08T22:05:48Z Indexed on 2012/11/08 23:15 UTC
Read the original article Hit count: 316

Filed under:
|

When I took the Realtime and Concurrent programming course our lecturer told us that when writing concurrent programs in Java and using monitors, most of the logic should be in the monitor and as little as possible in the threads that access it. I never really understood why and I really would like to.

Let me clarify.

In this particular case we had several classes.

Lift extends Thread
Person extends Thread
LiftView
Monitor, all methods synchronized.

This is nothing we came up with, our task was to implement a lift simulation with persons waiting on different floors, and theses were the class skeletons that were given.

Then our lecturer said to implement most of the logic in the monitor (he was talking about class Monitor as THE monitor) and as little as possible in the threads.

Why would he make a statement like that?

© Programmers or respective owner

Related posts about java

Related posts about concurrency