java.util.Timer를 Logging 라이브러리에서 사용을 하다보니, Logging라이브러리를 사용하고 있는 로깅서버에서 addShutdownHook() 메쏘드를 통해서 등록된 쓰레드가 실행이 안 된다.. ^^;;
Java API 문서를 보면, 아래와 같은 내용이 있습니다.
Timer 객체의 마지막 라이브 참조가 종료해, 미처리의 태스크가 모두 실행되면, 타이머의 태스크 실행 thread도 동시에
완료해, 가비지 컬렉트됩니다. 다만, 이것에는 한없고 긴 시간이 걸리는 경우가 있습니다. 디폴트에서는 태스크의 실행 thread는 「demon
thread」로서는 실행되지 않기 때문에 어플리케이션이 종료하지 않게 할 수 있습니다. 타이머의 태스크 실행 thread를 즉시 완료시키는
경우, 호출측은 타이머의 cancel 메서드를 호출할 필요가 있습니다.
흠... 그렇군요.. 종료가 안되더군요... ^^;;
그래서, Timer() 대신 daemon으로 Timer객체를 생성하면, addShutdownHook() 메쏘드에 등록된 쓰레드의 run() 메쏘드가 잘 동작하더군요.. ^^;;
sjava-logging library는 level에 따른 로깅 가능여부를 체크하고 있지는 않습니다.
아래의 Level은 로깅파일의 분류 및 파일의 내용에 기입을 하기 위한 클래스입니다.
그리고, Level에 대한 사용을 위해서는 LevelFactory를 사용하면 됩니다.
LevelFactory.java
package net.sjava.logging;
import java.util.Map;
import java.util.HashMap;
/**
*
* @author mcsong@gmail.com
* @since 2009. 7. 1.
*/
public class LevelFactory {
/** map of levels */
private Map<String, Level> levelMap;
this.levelMap.put("all", new Level(0, "all"));
this.levelMap.put("fatal", new Level(1, "fatal"));
this.levelMap.put("error", new Level(2, "error"));
this.levelMap.put("warn", new Level(3, "warn"));
this.levelMap.put("info", new Level(4, "info"));
this.levelMap.put("debug", new Level(5, "debug"));
this.levelMap.put("trace", new Level(6, "trace"));
this.levelMap.put("system", new Level(7, "system"));
}