Runtime.getRuntime().addShutdownHook怎么没起作用?
dfczj 2006-12-09 01:53:54 public class SingleInstance {
/**
* @param args
*/
public static void main(String[] args) {
try{
java.net.ServerSocket server=new java.net.ServerSocket(12345);
}catch(Exception e){
System.out.println("single");
System.exit(0);
}
try{
Thread.sleep(10000000L);
Runtime.getRuntime().addShutdownHook(new Thread(){
public void run(){
System.out.println("bye!");//手动关闭程序,这个bye!总是打不出来,那里有错?
}
});
}catch(Exception e){}
}
}