전체 글 (229) 썸네일형 리스트형 [스레드] 9. 스레드 그룹 스레드 그룹 - 관련된 스레드를 묶어서 관리할 목적으로 이용 - 스레드 그룹은 계층적으로 하위 스레드 그룹을 가질 수 있다. - 자동 생성되는 스레드 그룹 * system 그룹: JVM 운영에 필요한 스레드들을 포함 * system/main 그룹: 메인 스레드를 포함 - 스레드는 반드시 하나의 스레드 그룹에 포함 * 기본적으로 자신을 생성한 스레드와 같은 스레드 그룹에 속하게 된다. * 명시적으로 스레드 그룹에 포함시키지 않으면 기본적으로 system/main 그룹에 속한다. 스레드 그룹 이름 얻기 ThreadGroup group = Thread.currentThread.getThreadGroup(); Stirng gruopName = group.getName(); 예제) package ex08_thre.. [스레드] 8. 데몬 스레드 데몬(daemon) 스레드 주 스레드의 작업을 돕는 보조적인 역할을 수행하는 스레드 주 스레드가 종료되면 데몬 스레드는 강제적으로 자동 종료 ex) 워드프로세서의 자동저장, 미디어플레이어의 동영상 및 음악 재생, 가비지 컬렉터 데몬 스레드 설정 주 스레드가 데몬이 될 스레드의 setDaemon(true)를 호출 public static void main(String[] args) { AutoSaveThread thread = new AutoSaveThread(); thread.setDaemon(true); thread.start(); } -> 반드시 start() 메소드 호출전에 setDaemon(true) 호출필 데몬스레드확인 방법 isDaemon() 예제) 메인메소드 종료시 데몬스레드도 종료되는지 확.. [스레드] 7. 스레드 상태제어 예제1: 생산자스레드가 데이터를 만들면, 소비자스레드가 읽는다. package ex05_wait_notify; public class WaitNotifyExample { public static void main(String[] args) { DataBox dataBox = new DataBox(); ProducerThread producerThread = new ProducerThread(dataBox); ConsumerThread consumerThread = new ConsumerThread(dataBox); producerThread.start(); consumerThread.start(); } } 실행결과: ProducerThread가 생성한 데이터: Data-1 ConsumerThread가 읽.. 이전 1 ··· 4 5 6 7 8 9 10 ··· 77 다음