06.08.2013 Views

JAVA-BASED REAL-TIME PROGRAMMING

JAVA-BASED REAL-TIME PROGRAMMING

JAVA-BASED REAL-TIME PROGRAMMING

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2. Fundamentals<br />

useful. Note that even if an active object calls member functions of other<br />

(active or passive) objects, the execution of those functions is driven by<br />

the calling thread, and the stacked activation records are part of the<br />

callers execution state.<br />

8. A thread object with implicit mutual exclusion is called a task. This<br />

abstraction can be found in the Ada language.<br />

The abstractions supported by different programming languages differs. Concurrency<br />

in the Ada language is based on the task, which in that language<br />

is augmented with a specification of how such objects interact. Modula-2<br />

provides coroutines with pre-emption which allows a pre-emptive scheduler<br />

(supporting threads) to be built. Simula provides coroutines that, together<br />

with interrupts checked between each statement, can be used to build a scheduler<br />

and thread support. Neither Simula nor Modula support implicit mutual<br />

exclusion, which means that shared data must be explicitly reserved by calling<br />

certain functions for locking and unlocking. In C and C++, there is no<br />

concurrency support at all.<br />

2.6.2 Concurrency in Java<br />

So, what are then the design choices for Java? As with other parts of Java,<br />

we find fair engineering choices rather than new unique features.<br />

• There is no implicit mutual exclusion on object level, but individual<br />

methods (and even blocks) implicitly provide mutual exclusion by the<br />

explicit use of the synchronized keyword. Unfortunately, only code and<br />

not the accessed data is synchronized. Some extra programming discipline<br />

is therefore still required. Compared to having implicit mutual<br />

exclusion fully built into the language, the advantage is that the programmer<br />

is more free to tailor his/her code for specific application needs<br />

(such as efficiency).<br />

• The notion of a thread object is supported via the object orientation by<br />

inheritance from the Thread base-class. When inheritance is rather used<br />

for other properties (recall that Java only provides single inheritance),<br />

the interface Runnable can be used to add the thread property to an<br />

object.<br />

• Coroutines are not supported. Normally, threads are used to achieve the<br />

parallel behavior of coroutines. Therefore, large-scale event-driven simulations<br />

may be very inefficient/slow. 2 In normal applications, including<br />

2 To overcome this (unusual) problem, a superset of the Java language and a dedicated<br />

compiler and run-time system (replacing the JVM) could be developed. By implementing<br />

the language extensions as a translator implemented in Java, generating ordinary Java-code,<br />

the application would still be 100% Java when not optimized.<br />

34 2012-08-29 16:05

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!