JAVA-BASED REAL-TIME PROGRAMMING
JAVA-BASED REAL-TIME PROGRAMMING
JAVA-BASED REAL-TIME PROGRAMMING
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
3. Multi-Threaded Programming<br />
To improve on these aspects, communication via messages (instead of via<br />
methods and shared data) will be introduced in this section. Originally and<br />
traditionally, this was referred to as mailboxes.<br />
From one point of view, a so called mailbox is nothing but a special type of<br />
monitor, so we do not need any additional support from the language (no new<br />
keywords like synchronized which supports monitors). From another point of<br />
view, when the above aspects are important, message based object interaction<br />
can be considered to be fundamental, so let us start with some considerations<br />
about the abstraction we deal with.<br />
3.4.1 More on object interaction<br />
Method calls in a language/system providing only passive objects are by definition<br />
a synchronous type of communication. That is, passive objects work<br />
synchronously since they share the same thread of execution. In other words,<br />
this type of communication between objects is synchronous since the called<br />
object remains in its well defined state during the data transfer.<br />
During a method call, the caller enters the scope of the method within<br />
the scope of the called object, performing exactly what the method states. In<br />
a single-threaded system this is fine; data access via methods provide encapsulation<br />
and data abstraction. When all objects are executed by the same<br />
thread, we actually do not think of any thread at all. Data is transferred via<br />
arguments and return values, in both directions between the objects, which is<br />
straightforward and efficient in single-threaded applications.<br />
To support multi-threaded applications, the programming language could<br />
provide active (concurrently executing) objects, and models other than method<br />
calls for data transfer between objects. In fact, within object-oriented programming<br />
in general, communication between objects are (as in the language<br />
Smalltalk) often referred to as message passing. In Java, object interaction<br />
stems from the traditional (computationally efficient) C/C++ approach with<br />
method calls which are basically the same as function calls in C. Hence, in<br />
Java as well as in most other languages, asynchronous communication should<br />
be accomplished by a class implementing some type of mailbox or buffer supporting<br />
the principle of message passing.<br />
Thinking about real-life actors, sending a message is a natural way of transferring<br />
information, in particular when the sender and the receiver are acting<br />
concurrently but not synchronized (that is, performing actions independently<br />
of each other). The message need to be temporarily stored (buffered) somehow<br />
after being sent until being received. Today, information is most often stored<br />
and transmitted electronically. On the Internet, messages between humans<br />
are mainly accomplished by e-mail, but in technical systems we also use many<br />
other message principles depending on application and development needs.<br />
86 2012-08-29 16:05