Technical information
July 15, 2008 G24 KJAVA User’s Guide C-1
Appendix C: GPIO Interrupt Latency
Introduction
In order to achieve minimal average interrupt latency (HW I/O to Java) one should understand
JVM limitation, and how to manipulate code accordingly.
Java VM provides limited RT abilities. Programming in a multithreading environment while
trying to ensure strict RT scheduling, is an impossible mission. As a result, working in such an
environment will cause interrupt latency to be inconsistent, specially when parallel threads
consume large amount of VM resource (i.e. +UDP or HTTP connection).
Multithreading Background
A basic understanding of how to use threads is the key to writing effective J2ME applications.
Some important issues about multithreaded environments are listed below:
1. Scheduling
Thread scheduling is a complicated affair over which the application has little control. The
KVM scheduler allocates byte code slot for current running thread (classical OS uses run
time slot). It impossible to ensure fix run time for a fixed number of bytes code slot.
2. Priority
The only real influence the application has over thread scheduling is via the thread's priority
level: higher-priority threads execute more often than those with lower priority (default
thread priority is NORAML PRIORITY).
A thread keeps running until:
• It yields by calling the yield method
• The scheduler selects new thread to run
3. Garbage collection
Has higher priority then any other user thread, therefore will always have precedence over
user thread.
This behavior may cause inconsistent interrupt performance.
How To Achive Minimal Latency
Limited control over JVM scheduling mechanism can be achieved using Thread class:
• Thread.setPriority(priority level) -
This method enables user to adjust, in runtime, the current thread priority (range is from
MIN_PRIORITY to MAX_PRIORITY).