Technical information

Code Example
C-2 G24 KJAVA User’s Guide July 15, 2008
Thread.yield() -
This method enforces current thread to give up the CPU resource.
In order to create minimal average interrupt latency, one should set interrupt thread
(NativeExtEventThread) priority to the maximum level, other threads to the lower one and limit
those threads execution time by using yield function (if not used, interrupt thread can be delayed
for a significant amount of time: 40-50 milliseconds).
Code Example
The following code example demonstrates the use of the above sections:
public class myMidlet extends MIDlet implements GpioInterruptListener{
void startApp(){
// Define gpio 15 as input and enable interrupts on it.
GpioInput gpioInput = new GpioInput(15);
GpioInterruptConfig gpioInterruptConfig = new GpioInterruptConfig(this);
gpioInterruptConfig.enableDebounce(false);
gpioInterruptConfig.setNotificationType(GpioInterruptCon-
fig.NOTIFICATION_TYPE_LOW_TO_HIGH);
gpioInput.enableInterrupt(gpioInterruptConfig);
// Start the HTTPConnection thread.
HTTPConnection myHttp = new HTTPConnection("http://www.domain.com");
myHttp.start();
}
public void onInterrupt(int gpioNum, boolean val) {
// Set onInterrupt thread priority to MAX priority.
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
}
// HTTPConnection is used to demonstrate VM resource consuming thread.
protected class HTTPConnection extends Thread{
private String url ;
private HttpConnection conn;
private InputStream iStream;
public HTTPConnection(String Url){
// Set HTTP connection thread priority to MIN priority.
this.setPriority(this.MIN_PRIORITY);
this.url = Url;
}
public void run(){
conn = (HttpConnection)Connector.open(url,Connector.READ, true);
iStream = conn.openInputStream();
while(true){
iStream.read();
// HTTPConnection thread yield the CPU after each reading.
this.yield();
}
}
}
}