I am very new to java and only start to use Eclipse to run some real-time java program. I could not find javax.realtime
to import, I get the error:
The import javax.realtime cannot be resolved
Any idea how to resolve this? Do I need to download any extra package or change some project setup?
This package is not a part of built in packages. You will need additional Jar file for this package.
Check this link out.
Yes, you need a real-time Java library.
There are some intended for embedded systems, a commercial version from Oracle with a trial download, etc.
Note that, to actually get real-time performance out of any javax.realtime package (which implements the Real Time Specification for Java) you'll almost certainly also require 1) a JVM that's modified to work with that javax.realtime package, and 2) to run on a real-time operating system.
What JVM are you currently using? If it happens to be IBM WebSphere Real Time (which is available for free on developerworks at https://www.ibm.com/developerworks/java/jdk/linux/download.html : look for WebSphere Real Time V3 for RT Linux), then you'll also need to specify -Xrealtime on your java command line to run Java programs that use javax.realtime classes.
Well, the use of Java language in real-time systems (RTS) isn't widespread for a number of significant reasons. These include the non-deterministic performance effects inherent in the Java language's design, with dynamic class loading, and in the Java Runtime Environment (JRE) itself, with the garbage collector and native code compilation. So, the Real-time Specification for Java (RTSJ) is an open specification that potentiates the Java language to open a more widely door and use the language to build real-time systems.
Real-time (RT) is a broad term used to describe applications that have real-world timing requirements. For example, a non-responsive user interface, which doesn't satisfy an average user's generic RT requirements. This type of application is often described as a soft RT application. The same requirement might be more explicitly phrased as "the application should not take more than 0.1 seconds to respond to a mouse click." If the requirement isn't met, it's a soft failure: the application can continue, and the user, though unhappy, can still use it.
Now, implementing the RTSJ requires support from the operating system, the vitual machine or JRE, and the Java Class Library (JCL).
A real-time operating system (RTOS) is an operating system (OS)
intended to serve real-time applications that process data as it comes
in, typically without buffer delays.
...
A key characteristic of an RTOS is the level of its consistency
concerning the amount of time it takes to accept and complete an
application's task; the variability is jitter.
The important thing is that jitter is quantified for the system to be considered real time. From this Wikipedia article, we know that if the jitter is usually bounded, the system is soft real-time. If the jitter is always bounded, the system is hard real-time.
Standard Java applications running on a general-purpose JVM on a general-purpose operating system can only hope to meet soft RT requirements at the level of hundreds of milliseconds. Several fundamental aspects of the language are responsible: thread management, class loading, Just-in-time (JIT) compiler activity, and garbage collection (GC). Some of these issues can be mitigated by application designers, but only with significant work.
You can download a RT implementation from IBM for Java 8 here.
Also you can find more information in this document.