New Java threading model for real-time system concurrent programming, remember my first English translation

Source: Internet
Author: User

1: Introduction:

The traditional real-time system is the domain of experienced experts, as they can handle a variety of custom kernels, nonstandard and mostly low-level languages, vendor-supplied custom I/O interfaces. This requires a new Java threading model to address this situation, which solves the four flaws that are currently embedded in the system in a timely manner: security, performance, portability. Program debugging time. Security is a compromise between the current programming language and a timely system in terms of complexity and ambiguous interfaces, which cannot be formally a system-safe syntax; performance is compromised because engineers must accept whatever level of action is provided by the system in a timely manner, If those operations are too high or too low to cause unnecessary daily overhead, the increase in portability is due to the current tooling provided by vendors, and the time to develop a timely embedded system is hampered by the lack of communication processor and hardware interface development tools.

We introduced the CSP channel, which is a form of communication that is connected using Java, which can be used as a Java class or can be downloaded from our website (http://rt.el.utwente.nl/javapp (link is wall or defunct)). The use of Java to develop a timely system is considered disruptive, as presented by the expert on real-time systems design, as the instant system embodies a subset of Java's flaws in the build.

The main disadvantage of Java is that: Dynamic memory management, threading model, the lack of direct, responsible and timely response to environmental changes, can be summarized as below three points:

1:java contains several dynamic components that can compromise the deadline of the process, for example, in Java, the concept of cloning requires dynamic memory allocation, and is independent of memory recycling, other components, such as ClassLoader, network methods also use dynamic memory management, for the development of timely embedded systems, It is important that behavior is decisive, usually static memory allocations are used, and for several groups working on a unified garbage collection, it is difficult to evade garbage collection.

2:java monitors can operate statically and correctly, but live locks are starved, and there may be deadlocks due to the addition of special time limits, and Java monitors are inefficient, dangerous, through the Java Threads in the light of CSP. In the implementation of the current Java monitor, when a thread wakes up by another thread, it is at the very end of the serialized queue, and it is possible that a particular thread will never wake up from the queue, and the result is a live lock waiting indefinitely, starved, and because of this, a correct implementation must be provided.

3: Timely scheduling as part of the RTOS (real-time OS), and there is no need to make a timely system, a timely system should be able to the upcoming stimuli, such as clock response, Java does not interrupt the device, so must implement an RTOS, At the level of the operating system we have to solve a lot of things, on the other hand, Java should also reflect its object-oriented features.

We have developed Java thread Communication classes that can solve the above problems using formal methods, the general concept is independent of mathematical algebra, programming languages, and arithmetic, these technologies contain formal technology, they have been used in a timely embedded system for many years, using this concise rules, In design and implementation can avoid live lock, starve, deadlock, this concept provides the possibility of developing a part of the design pattern, using these methods we can guarantee the behavior of the system, in other words, the formal method is necessary for the development of a reliable system, we limit our use of the concept of CSP in the above mentioned timely problems.

Here, section 2 introduces the CSP channel, the use of open source channels we will introduce in section 3, in section 4 letter of introduction concept and timely behavior, in section 5 scheduling method Jiangbei Discussion, section 6 summarize the method of using CSP in time embedded system.

2: Channel Programming:

The CSP concept provides a different concurrency model than the Java threading model, known as a channel, for synchronization through interprocess communication.

The Java channel is the middle object shared by active objects, threads or processes, see how they communicate the channel is unidirectional, initially not buffered and synchronized, which is described in Figure 1, the active object can only be read or written on the channel, after both processes are ready to start communication, The process is blocked until the communication is ready, synchronized, dispatched, and the physical data is transmitted encapsulated into the channel:

The channel model reduces the problem between concurrent design and implementation, figure 2 represents the data flow model at the design level:

In a streaming diagram, an arrow represents a response between channels, one-way representation of input and output interfaces is recyclable but one-way when the input/output channel is processed.

The following code is used to do the case:

import cjt.*;  Public class main{    publicstaticvoid  Main (string[] args)    {        new  Channel ();         New Processa (channel);         New PROCESSB (channel);    }}

Here Main () plays the key, it declares the channel and process, this method does not have the loop structure, on the contrary, the less complex cycle is saved in the process, this main class represents the concurrent programming of a processor, it is important that the process will remain unchanged and the channel has media and processor information.

In the following two examples, we list PROCESSA,PROCESSB, which generates 10,000 numbers from 0 to 9999, and then processb the 10,000 numbers to the screen:

Importcjt.*;Importjava.io.IOException; Public classProcessaextendsprocessobject{channeloutput Channel;  PublicProcessa (Channeloutput out) {channel=Out ;    Start (); }     Public voidrun () {Integerobject object=NewIntegerobject (); Seqcomposition seq=Newseqcomposition (); Try        {             while(Object.value < 10000) {Object.value++;            Channel.write (Seq, object); }        } Catch(IOException e) {}Catch(Interruptedexception e) {} }}

Listing 2. Producer Processa.

Importcjt.*;Importjava.io.IOException; Public classProcessbextendsprocessobject{channelinput Channel;  PublicPROCESSB (Channelinput in) {channel=In ;    Start (); }     Public voidrun () {Integerobject object=NewIntegerobject (); Seqcomposition seq=Newseqcomposition (); Try        {             while(Object.value < 10000) {channel.read (Seq, object);            System.out.println (Object.value); }        } Catch(IOException e) {}Catch(Interruptedexception e) {} }}

This read (), write () method consists of two parameter seq,object. This seqcomposition instance of SEQ, which indicates a serialized behavior Read,write method, where parcomposition,altcomposition parallel behavior exists.

The channel is thread-safe for most read and write, most producers and consumers will occupy the same channel, the channel also shows that the scheduling between different threads has priority, the priority can be changed through communication, naturally, one-on, a multi-pair relationship can be implemented.

3: Open Source

The concept of the channel is out of communication in Java, the Java Development Suite does not have the framework to call the hardware directly support, only through jni,jni too much will lead to the Java platform portability, the channel is to define an abstract method control device, hardware, in the face of objects can increase reusability, The channel will use a shared memory driver between processing processes, and the result is that the process is independent of the hardware:

In order to avoid the development of a special channel for each peripheral device, the device driver we can connect the driver, that is, those hardware independent objects can be fed into the channel, the channel object can handle serialization and scheduling for data transmission protection, the channel object is hardware independent, the result, this link drive will be serialized, scheduling, and it's easier to program.

When serialization is allowed, this read (), write () enters the thread object, the delegate link driver, Figure4 shows a processor communicating between the two processes, and FIGURE5 shows the communication between the two systems:

Declares that a channel uses a link driver:

Channel Chan = new Channel (new Mylinkdriver ());

Hardware-independent objects can be found in a declared channel.

4: Real-time aspects:

For today's real-time system, time is one of the most important factors, from the point of view of demand, we only consider the limit time, the user considers only when the system responds to certain stimuli, regardless of the response to the archived daemon or foreground program, how to dispatch the related tasks, and how to implement the controller, from this point of view, Time is the only signal related, this environment diagram is the data flow diagram, in the environment diagram, the arrow is the channel communication occurrence special time, this makes the channel is more important for the timely system.

The channel concept provides the realization of timely requirements as follows:

Non-deterministic in 1:java occurs when cloning objects and objects is serialized, along with garbage collection is avoided, when using the channel;

2: Special link drivers may extend timing through the channel behavior, a link file contains a buffer that may mitigate inversion of the problem of consolidation using priority arrangements;

3: The process of meeting the priority requirements resulted in the philosophy of interrupt processing was born;

4: The channel can optimize the process with the same priority, but it can also be different in the priority level.

5: Embedded Schedule:

The scheduling of threads belongs to the application to run his tasks in parallel, so a schedule is not required by the operating system; a schedule as an operating system resource should be multi-tasking, we can inherit this concept, an operating system is also a parallel program, in other words, There is a lot of time in the execution, that is, different programs can run alone in its own way, an embedded schedule can switch a process to a number of different tasks. A parallel program consists of a large number of objects that must be arranged, meaning that the current program needs to be embedded in time to implement multithreading.

6: Summary:

Using CSP channel design in an instant system provides a framework to clean up the programmer away from complex, non-essential programming tasks, such as threading programming or scheduling, the approach presented here is a solution for deadlocks, starvation, and the concept of priority should be considered the priority of communication between processes rather than the priority of the thread.

This result makes programming very simple and easy to maintain, the final code is similar to the Java code in the same case, after learning the CSP can be designed to be simple and have a brisk speed, there is a performance improvement space and make Java programming in a timely system easier, And the Java channel does not require a garbage collection mechanism. (2014.4.11)

New Java threading model for real-time system concurrent programming, remember my first English translation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.