###質問内容
eclipseを使用してjavaのマルチスレッド(3つ)を作る課題をやっているんですが,現段階ではスレッドごとにクラスを作り処理を行っています。
最終的には一つのクラスの中で処理を行いたいんですが、どのようにしたらいいのかわかりません。
どのようにしたらよいでしょうか教えてください。
###該当のソースコード
public class multiThread {
public static void main(String args[]){ SubThread1 sub = new SubThread1(); SubThread2 sub2 = new SubThread2(); sub.start(); sub2.start(); for (int i = 0 ; i < 100 ; i++){ System.out.println("Hello world"); try{ Thread.sleep(100); }catch(InterruptedException e){ } } }
}
class SubThread1 extends Thread{
public void run(){
for (int i = 0 ; i < 100 ; i++){
System.out.println("Hello world1");
try{
Thread.sleep(100);
}catch(InterruptedException e){
}
}
}
}
class SubThread2 extends Thread{
public void run(){
for (int i = 0 ; i < 100 ; i++){
System.out.println("Hello world2");
try{
Thread.sleep(100);
}catch(InterruptedException e){
}
}
}
}
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。