可能性の重複:
java thread - run() and start() methodsthread.run()の代わりにthread.start()を呼び出す必要があるのはなぜですか?
私は今、私の質問はTHAである
public class ThreadTest{
public static void main(String[] args){
MyThread newthread=new MyThread();
Thread t=new Thread(newthread);
t.start();
for(int x=0;x<10; x++){
System.out.println("Main"+x)
}
}
}
class MyThread implements Runnable{
public void run(){
for(int x=0; x<10; x++){
System.out.println("Thread"+x);
}
}
}
---スレッド使用するプログラムを作っt ...なぜ「スレッド」クラスを使用してオブジェクトを作成し、そのコンストラクタに「MyThread」コールを渡すのですか? 「MyThread」オブジェクトのrunメソッドを、オブジェクトを作成してrunメソッドを呼び出して呼び出すことはできませんか?
(すなわちMyThread newthread=new MyThread(); and then newthread.run();
)
トレッドオブジェクトを作成し、それにMyThreadクラスを渡すための理由は何ですか?
- それはどのように役立ちますか? –
私が知りたいことは...なぜ私はスレッド、すなわちメインスレッドではなく複数のスレッドを作成したいのですか? –
@IamAあなたはJavaに複数のスレッドを作成する必要はないと言っていますか? –