방금 주 스레드를 포함한 세 개의 스레드로 카운트 다운 앱을 만들었습니다. 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