You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
스레드의 기본 정보
1. 스레드 기본 정보
1) 스레드 생성 및 기본 출력
Thread myThread = new Thread(new HelloRunnable(), "myThread");Runnable구현체로 전달한다.Thread.currentThread()main()메서드에서는 메인 스레드가 반환된다.log("mainThread = " + mainThread);Thread[#1,main,5,main]2) 스레드 아이디
myThread.threadId()3) 스레드 이름
myThread.getName()4) 우선순위
myThread.getPriority()setPriority()메서드를 사용하면 우선순위를 변경할 수 있다.5) 스레드 그룹
myThread.getThreadGroup()main()스레드가 생성한 스레드는 모두 main 그룹에 속한다.5) 스레드 상태
myThread.getState()Thread.State열거형에 정의되어 있다.A. 주요 스레드 상태
NEW: 스레드가 생성되었지만 아직 start()가 호출되지 않은 상태이다.RUNNABLE: 실행 중이거나 실행 준비가 된 상태이다.BLOCKED: 동기화 블록(lock)을 획득하기 위해 대기 중인 상태이다.WAITING: 다른 스레드의 작업이 완료되기를 무기한 기다리는 상태이다.TIMED_WAITING: 일정 시간 동안만 기다리는 상태이다.TERMINATED: 스레드의 실행이 종료된 상태이다.B. 실행 시점의 상태 변화
NEW이다.start()메서드를 호출하면RUNNABLE상태로 전환된다.run()메서드가 종료되면TERMINATED상태로 변경된다.All reactions