Search in sources :

Example 1 with ClassLoaderLogManager

use of org.apache.juli.ClassLoaderLogManager in project tomcat by apache.

the class SetParentClassLoaderRule method start.

/**
     * Start a new server instance.
     */
public void start() {
    if (getServer() == null) {
        load();
    }
    if (getServer() == null) {
        log.fatal("Cannot start server. Server instance is not configured.");
        return;
    }
    long t1 = System.nanoTime();
    // Start the new server
    try {
        getServer().start();
    } catch (LifecycleException e) {
        log.fatal(sm.getString("catalina.serverStartFail"), e);
        try {
            getServer().destroy();
        } catch (LifecycleException e1) {
            log.debug("destroy() failed for failed Server ", e1);
        }
        return;
    }
    long t2 = System.nanoTime();
    if (log.isInfoEnabled()) {
        log.info("Server startup in " + ((t2 - t1) / 1000000) + " ms");
    }
    // Register shutdown hook
    if (useShutdownHook) {
        if (shutdownHook == null) {
            shutdownHook = new CatalinaShutdownHook();
        }
        Runtime.getRuntime().addShutdownHook(shutdownHook);
        // If JULI is being used, disable JULI's shutdown hook since
        // shutdown hooks run in parallel and log messages may be lost
        // if JULI's hook completes before the CatalinaShutdownHook()
        LogManager logManager = LogManager.getLogManager();
        if (logManager instanceof ClassLoaderLogManager) {
            ((ClassLoaderLogManager) logManager).setUseShutdownHook(false);
        }
    }
    if (await) {
        await();
        stop();
    }
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) ClassLoaderLogManager(org.apache.juli.ClassLoaderLogManager) LogManager(java.util.logging.LogManager) ClassLoaderLogManager(org.apache.juli.ClassLoaderLogManager)

Example 2 with ClassLoaderLogManager

use of org.apache.juli.ClassLoaderLogManager in project tomcat by apache.

the class SetParentClassLoaderRule method stop.

/**
     * Stop an existing server instance.
     */
public void stop() {
    try {
        // doesn't get invoked twice
        if (useShutdownHook) {
            Runtime.getRuntime().removeShutdownHook(shutdownHook);
            // If JULI is being used, re-enable JULI's shutdown to ensure
            // log messages are not lost
            LogManager logManager = LogManager.getLogManager();
            if (logManager instanceof ClassLoaderLogManager) {
                ((ClassLoaderLogManager) logManager).setUseShutdownHook(true);
            }
        }
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
    // This will fail on JDK 1.2. Ignoring, as Tomcat can run
    // fine without the shutdown hook.
    }
    // Shut down the server
    try {
        Server s = getServer();
        LifecycleState state = s.getState();
        if (LifecycleState.STOPPING_PREP.compareTo(state) <= 0 && LifecycleState.DESTROYED.compareTo(state) >= 0) {
        // Nothing to do. stop() was already called
        } else {
            s.stop();
            s.destroy();
        }
    } catch (LifecycleException e) {
        log.error("Catalina.stop", e);
    }
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) ClassLoaderLogManager(org.apache.juli.ClassLoaderLogManager) Server(org.apache.catalina.Server) LifecycleState(org.apache.catalina.LifecycleState) LogManager(java.util.logging.LogManager) ClassLoaderLogManager(org.apache.juli.ClassLoaderLogManager)

Aggregations

LogManager (java.util.logging.LogManager)2 LifecycleException (org.apache.catalina.LifecycleException)2 ClassLoaderLogManager (org.apache.juli.ClassLoaderLogManager)2 LifecycleState (org.apache.catalina.LifecycleState)1 Server (org.apache.catalina.Server)1