Thread

package hello.java.lang;

public class ThreadTest extends Thread {

private int sleeptime = 0;

// コンストラクタ

public ThreadTest(String name, int sleeptime) {

super(name);

if (sleeptime > 0) {

this.sleeptime = sleeptime;

}

}

public void run() {

for (int i = 0; i < 10; i++) {

// スレッド名とループ数を表示します

System.out.println(this.getName() + " : " + i);

try {

// sleeptimeミリ秒間スレッドを停止します

sleep(sleeptime);

} catch (InterruptedException e) {

}

}

}

public static void main(String[] args) {

// スレッドオブジェクトのインスタンスを生成

ThreadTest thread1 = new ThreadTest("Helloスレッド", 5000);

ThreadTest thread2 = new ThreadTest("Worldスレッド", 2500);

// スレッドを開始

thread1.start();

thread2.start();

}

}