멀티 스레딩에 익숙하며 몇 가지 질문과 혼란이 생겼습니다. :)멀티 스레딩 콘솔 출력이 다르다
public class NewThread implements Runnable {
Thread t;
NewThread() {
t = new Thread(this, "Demo Thread");
System.out.println("Child Thread " + t);
t.start();
}
@Override
public void run() {
try {
for (int i = 5; i > 0; i--) {
System.out.println("Child Thread: " + i);
Thread.sleep(500);
}
} catch (InterruptedException e) {
System.out.println("Child Interrupted.");
}
System.out.println("Exiting Child Thread.");
}
}
class ThreadDemo {
public static void main(String[] args) {
NewThread t = new NewThread();
try {
for (int i = 5; i > 0; i--) {
System.out.println("Main Thread: " + i);
Thread.sleep(1000);
}
} catch (InterruptedException e) {
// TODO: handle exception
System.out.println("Main Thread Interrupted.");
}
System.out.println("Main Thread Exiting.");
}
}
예외 처리 출력
내 출력
왜 내 콘솔 출력이 예상 출력 다릅니 까? 고맙습니다.
당신은'NewThread t = new NewThread(); –
그래, 그렇게 보입니다. – AppSensei
src가 정상적으로 보인다. 그리고 당신의 근원을 실행할 수 있고 적당한 산출을 얻고있다. 여기에 게시 된 src가 테스트중인 src와 같은지 확인하십시오. – Jayamohan