アットウィキロゴ

☆実習課題☆ 5-1

class MyRunnable implements Runnable{
String name;
// コンストラクタ
public MyRunnable(String s){
name = s;
}
// オーバーライドされたrunメソッド
public void run(){
	while(true){
		System.out.println(name);
	}
}
}

class MyRunnableApp{
public static void main(String args[]){
// スレッドの作成
MyRunnable r1 = new MyRunnable("Runnable1");
Thread t1 = new Thread(r1);
MyRunnable r2 = new MyRunnable("Runnable2");
Thread t2 = new Thread(r2);
MyRunnable r3 = new MyRunnable("Runnable3");
Thread t3 = new Thread(r3);
// スレッドの実行開始
t1.start();
t2.start();
t3.start();
}
}
最終更新:2009年10月30日 23:16