私はちょうどメインスレッドを含む3つのスレッドでカウントダウンアプリを作った。 CountdownEvenを低く設定しておくと、countdownOddが最初に表示されますが、出力に何も起こっていません。誰もが問題を見ることができますか?優先度設定のスレッド
//Main
public class CountdownApp
{
public static void main(String[] args)
{
new CountdownApp().start();
}
public void start()
{
Thread count1 = new CountdownEven();
Thread count2 = new CountdownOdd();
count1.setPriority(Thread.MIN_PRIORITY);
count2.setPriority(Thread.MAX_PRIORITY);
count1.start();
count2.start();
}
}
public class CountdownEven extends Thread
{
public void run()
{
for(int i = 10; i > 0; i-=2)
{
System.out.println(this.getName()+ " Count: " +i);
Thread.yield();//This is to allow the other thread to run.
}
}
}
public class CountdownOdd extends Thread
{
public void run()
{
for(int i = 9; i > 0; i-=2)
{
System.out.println(this.getName()+ " Count: " +i);
Thread.yield();//This is to allow the other thread to run.
}
}
}
を参照してください。 –
私はあなたのコードを実行しました。出力は 'Thread-1 Count:9' /' Thread-1 Count:7'/'Thread-1 Count:5'などです。 – assylias
優先順位の使用は正しい方法ではありませんスレッドが実行される順序。 – assylias