- package tw.kuas.edu.tw;
- public class Main {
- public static void main(String[] args) throws InterruptedException {
- // TODO 自動產生的方法 Stub
- System.out.println("Thread start.");
- Prog thread = new Prog();
- thread.start();
- System.out.println("Thread end.");
- }
- }
複製代碼- package tw.kuas.edu.tw;
- public class Prog extends Thread
- {
- public void run()
- {
- for(int i=100; i>=0; i--)
- {
- try {
- Thread.sleep(1000);
- System.out.println(i+"s!");
- } catch (InterruptedException e) {
- // TODO 自動產生的 catch 區塊
- e.printStackTrace();
- }
-
- }
- System.out.println("Time's up!");
- }
- }
複製代碼 |