Using real-time Java for development, part 1th explores the unique features of real-time Java

Source: Internet
Author: User
Tags file system garbage collection thread class advantage

Real-time Java is a set of enhancements to the Java language that provide the application with a degree of real-time performance that is not available in standard Java technology. Traditional throughput performance is usually a measure of the total number of instructions, tasks, or jobs that can be completed within a fixed amount of time. Unlike traditional throughput performance, real-time performance focuses on the time it takes for an application to respond to external stimuli without exceeding a given time constraint. In hard-time systems, it is impossible to exceed such constraints, and soft real-time systems have higher tolerance to violations. Real-time performance requires that the application itself control the processor so that it responds to stimuli, and that, while responding to the stimulus, the competition process within the virtual machine does not prevent the application code from executing. Real-time Java delivers unprecedented responsiveness in Java applications.

Real-time JVMs can leverage real-time operating system (real-time operating System,rtos) services to provide hard real-time functionality, or can run one or more traditional operating systems for applications with softer real-time constraints. When using a real-time JVM, you can use some of the techniques used in real time Java for free. But to explore some of the features in real-time Java, you need to make some changes to your application. These features are the focus of this article.

Child processes that must be constrained

The JVM service is a given application that performs work that can only be loosely controlled by the application. Some run-time child processes run within the JVM, including:

Garbage collection: This task is used to reclaim a block of run-time memory that the application no longer uses. Garbage collection enables application execution to be delayed for a period of time.

Class loading: This process (called Class loading because Java applications are loaded at the class granularity level) involves loading application structures, directives, and other resources from a file system or network. In standard Java, an application loads the class (deferred loading) the first time it references a class.

Just-in-time (JUST-IN-TIME,JIT) dynamic compilation: Many virtual machines interpret methods from Java bytecode as local machine directives by dynamic compilation when the application is running. Although this can improve performance, the compilation activity itself can cause temporary delays that prevent application code from running.

Scheduling: In standard Java, an application has minimal control over the scheduling of its own running threads, as well as scheduling applications related to other applications running on the same operating system.

All of these child processes can limit the ability of applications to respond to external stimuli because they can delay the execution of application code. For example, you can schedule a sequence of instructions to respond to signals from a network, radar system, keyboard, or any other device. Real-time applications have a very short acceptable period during which a unrelated process, such as garbage collection, is allowed to delay the execution of the response instruction sequence.

Real-time Java provides a variety of technologies designed to minimize the disruption of the underlying child processes to the application. The "free" technologies that are available when switching to a live JVM include: specialized garbage collection that limits the duration of the collection operation and the impact of disturbances, allows specialized class loading at startup, rather than deferred optimizations, and specialized priority thread scheduling that avoids priority reversal. However, you may need to make some modifications to your application, especially if you want to take advantage of the features introduced by the Java real-time specification (real-time specification for JAVA,RTSJ).

RTSJ provides an API that supports a large number of real-time features in the JVM. Some of the features are mandatory in the specification implementation and others are optional. The specification includes the following general areas:

Real-Time scheduling

Advanced Memory Management

High Precision Timer

Asynchronous event handling

Asynchronous thread interrupts

Realtime Thread

RTSJ defines a subclass of the javax.realtime.realtimethread-standard Java.lang.Thread class. Essentially, Realtimethread supports some of the advanced features in the specification. For example, a real-time thread is controlled by a real-time thread scheduler. The scheduler provides a unique scheduling priority range, you can implement a first-in-first-out real-time scheduling policy (ensure that the highest priority threads are not disturbed), as well as priority inheritance, which prevents lower-priority threads from holding indefinitely the locks required by higher-priority threads that need to run without interference. This situation is called priority inversion.

You can explicitly construct an instance of Realtimethread in your code. But you can also easily change your application to enable real-time threading to avoid heavy development effort and associated costs. Here is a sample of the various ways in which the least intrusive and most transparent real-time threading is enabled. These technologies make it easy for applications to take advantage of real-time threads, enabling applications to remain compatible with standard virtual machines.

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.