import sun.misc.Signal;
import sun.misc.SignalHandler;
public class Test {
public Test() {
Runtime.getRuntime().addShutdownHook(new ShutdownHookThread());
catchSig();
}
public static void main(String[] args) {
Test test = new Test();
try {
Thread.sleep(1000);
/*종료시킨다.*/
//System.exit(0);
System.exit(1);
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public class ShutdownHookThread extends Thread {
public ShutdownHookThread() {
System.out.println("HOOKed");
}
public void run() {
System.out.println("ShutdownHookThread Called Successfully!!!!");
}
}
public void catchSig(){
Signal.handle(new Signal("INT"), new SignalHandler () {
public void handle(Signal sig) {
System.out.println(
"Aaarggh, a user is trying to interrupt me!!");
System.out.println(
"(throw garlic at user, say `shoo, go away')");
}
});
for(int i=0; i<100; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.print('.');
}
}
}
'컴퓨터/IT' 카테고리의 다른 글
내손안의 PC 빌립 S5 (0) | 2009.03.30 |
---|---|
Microsoft Windows 2003 Server 최적화 설정하기 (0) | 2009.03.21 |
eclipse 3.4.2 & subversive (0) | 2009.03.12 |
윈도우에서 웹캠서비스하기 (0) | 2009.03.11 |
우분투 네트워크/하드디스크 자동 마운트 (0) | 2009.03.04 |