Java Reference
In-Depth Information
present in all Java ME implementations we have come across. There are,
in essence, three threads we need to know about:
the lifecycle thread
the event dispatcher thread
the painter thread.
The lifecycle thread invokes MIDlet lifecycle methods such as MIDlet.
startApp() , MIDlet.pauseApp() and MIDlet.destroyApp() .
Our rule in this case translates into avoiding any blocking operations
inside these methods, such as opening and reading streams, creating or
loading images, and so on. Such tasks should be performed in a separate
thread if at all possible. Consider this MIDlet startup example:
class MyLoader implements Runnable
MyMIDlet midlet = null;
public MyLoader(MyMIDlet midlet)
this.midlet = midlet;
// implementing abstract method run() from Runnable
public void run() {
// various long-running tasks, eg. load pictures
midlet.view = new MenuView();
class MyMIDlet extends MIDlet {
SplashScreen splash = new SplashScreen();
MenuView view = null;
protected void startApp() throws MIDletStateChangeException {
// sets the Display
// starts a new thread to load other views and data;
MyThread loader = new MyThread(this);
public void notifyDone() {
// at the end of processing set up display to be MenuView
// make the splash screen eligible for garbage collection
splash = null;
This is a typical example of neat application startup handling. The
system-called startApp() method completes immediately as it just sets
the current screen to a lightweight SplashScreen and launches a thread
Search WWH ::

Custom Search