Cep Terminals GSM/GPRS TERMINAL CT63 JAVA 6203 ユーザーズマニュアル

製品コード
6203
ページ / 109
Java User’s Guide
12.2 Programming the MIDlet
109
wm_java_usersguide_v19
Page 109 of 109
2012-01-27
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();
  }
}