The addShutdownHook method of Runtime class is vervy useful to invoke something before a application exit. In addition coding in JUnit, very useful.
If you create and use some Threads, you can not invoke directly, this method usage is very helpful.
public class Monitor {
private static Log log = LogFactory.getLog(HTMLPageFetcher.class);
private static NotificationCollector notiCollector;
static {
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
close();
}
});
}
public static void close() {
log.info("close application.!!");
notiCollector.stop();
}
...
...
'java core' 카테고리의 다른 글
Implementing equals method of collections classes (0) | 2009.04.27 |
---|---|
JavaOne 2008 (0) | 2009.04.17 |
JDK7에 clossloader의 close 메소드가 생기다니. (0) | 2009.04.09 |
JMX 에서 standardbean 사용 관련 Tip (0) | 2009.03.28 |
JMX를 통해서 cpu 정보 구하기 (0) | 2009.03.25 |