Java user’s guide – Siemens XT65 User Manual

Page 122

Advertising
background image

Java User’s Guide

13.2 Programming the MIDlet

122

s

wm_java_usersguide_v12

Page 122 of 123

2008-02-25

Confidential / Released

/* Print loop counter and wait 1 second,

* do something useful here instead */

System.out.println("Thread(" + loops + "): Loop " + i);

try {

Thread.sleep(1000);

} catch(InterruptedException e) {

System.out.println(e);

}

}

System.out.println("Thread(" + loops + "): Finished naturally");

}

}

/**

* ThreadDemo - constructor

*/

public ThreadDemo() {

System.out.println("ThreadDemo: Constructor, creating threads");

thread1 = new DemoThread(2);

thread2 = new DemoThread(6);

}

/**

* startApp()

*/

public void startApp() throws MIDletStateChangeException {

System.out.println("ThreadDemo: startApp, starting threads");

thread1.start();

thread2.start();

System.out.println("ThreadDemo: Waiting 4 seconds before stopping threads");

try {

Thread.sleep(4000);

} catch(InterruptedException e) {

System.out.println(e);

}

destroyApp(true);

System.out.println("ThreadDemo: Closing application");

}

/**

* pauseApp()

*/

public void pauseApp() {

System.out.println("ThreadDemo: pauseApp()");

}

/**

* destroyApp()

*/

public void destroyApp(boolean cond) {

System.out.println("ThreadDemo: destroyApp(" + cond + ")");

System.out.println("ThreadDemo: Stopping threads from outsdide");

runThreads = false;

try {

System.out.println("ThreadDemo: Waiting for threads to die");

thread1.join();

thread2.join();

} catch(InterruptedException e) {

System.out.println(e);

}

System.out.println("ThreadDemo: All threads died");

notifyDestroyed();

}
}

Advertising
This manual is related to the following products: