我的main方法中包含以下内容:
public static void main(String[] args) throws IOException {
    Properties properties = getConfig();
    Jedis jedis = configure(properties)
    jedis.subscribe(queueHandler, "queue");
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            logger.debug("SHUTTING DOWN");
            jedis.close();
        }
    });
}我注意到我的关闭钩子里的代码从来没有运行过,为什么呢?如何清理我的main方法拥有的资源?
发布于 2016-04-02 20:05:57
Main方法的常规退出与显式调用System.exit(0);略有不同
因此,尝试如下所示:
public static void main(String[] args) throws IOException {
    //all your code...
    System.exit(0); //NOTE: non zero status will work different!
}https://stackoverflow.com/questions/36369453
复制相似问题