Raven 连接 java.lang.IllegalStateException:正在关闭

Raven connection java.lang.IllegalStateException: Shutdown in progress

我有一个非常基本的程序,可以连接到 PostgreSQL 数据库并测试 Sentry 日志记录是否有效。

但我无法正常关闭它。 我做错了什么?

package com.sample;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

public class Main {
    private static final Logger logger = LogManager.getLogger(Main.class);

    public static void main(String[] args) {

        logger.error("Random error");
        logger.trace("Exiting application.");
    }
}

我得到这个异常:

2015-12-13 16:13:31,914 pool-1-thread-1 ERROR An exception occurred while closing the Raven connection java.lang.IllegalStateException: Shutdown in progress
    at java.lang.ApplicationShutdownHooks.remove(ApplicationShutdownHooks.java:82)
    at java.lang.Runtime.removeShutdownHook(Runtime.java:239)
    at net.kencochrane.raven.connection.AsyncConnection.close(AsyncConnection.java:92)
    at net.kencochrane.raven.Raven.closeConnection(Raven.java:112)
    at net.kencochrane.raven.log4j2.SentryAppender.stop(SentryAppender.java:303)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.stop(AbstractConfiguration.java:313)
    at org.apache.logging.log4j.core.LoggerContext.stop(LoggerContext.java:303)
    at org.apache.logging.log4j.core.LoggerContext.run(LoggerContext.java:262)
    at org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry.run(DefaultShutdownCallbackRegistry.java:100)
    at org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry.run(DefaultShutdownCallbackRegistry.java:74)
    at java.lang.Thread.run(Thread.java:745)

顺便说一句,将 raven.async.gracefulshutdown 设置为 false 没有帮助。

项目主页https://github.com/getsentry/raven-java

问题出在 raven-java 本身,我已经创建了拉取请求,现在已修复。

https://github.com/getsentry/raven-java/pull/166

您可以像这样使用最新的 Sentry:

<repository>
    <id>sonatype-nexus-snapshots</id>
    <name>Sonatype Nexus Snapshots</name>
    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    <releases>
        <enabled>false</enabled>
    </releases>
    <snapshots>
        <enabled>true</enabled>
    </snapshots>
</repository>

<dependencies>
    <dependency>
        <groupId>net.kencochrane.raven</groupId>
        <artifactId>raven-log4j2</artifactId>
        <version>6.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>