beautypg.com

Siemens TC65 User Manual

Page 89

background image

TC65 JAVA User's Guide
Strictly confidential / Released

s

TC65 JAVA User's Guide_V05

Page 89 of 90

26.09.2005

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");
notifyDestroyed();
}

/**
* 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");
}
}