Example usage for org.apache.hadoop.util ExitUtil halt

List of usage examples for org.apache.hadoop.util ExitUtil halt

Introduction

In this page you can find the example usage for org.apache.hadoop.util ExitUtil halt.

Prototype

public static void halt(int status) throws HaltException 

Source Link

Document

Forcibly terminates the currently running Java virtual machine.

Usage

From source file:org.apache.slider.core.main.ServiceLauncher.java

License:Apache License

/**
 * Uncaught exception handler.//from  w  w  w.  ja v  a2s .com
 * If an error is raised: shutdown
 * The state of the system is unknown at this point -attempting
 * a clean shutdown is dangerous. Instead: exit
 * @param thread thread that failed
 * @param exception exception
 */
@Override
public void uncaughtException(Thread thread, Throwable exception) {
    if (ShutdownHookManager.get().isShutdownInProgress()) {
        LOG.error("Thread {} threw an error during shutdown: {}.", thread.toString(), exception, exception);
    } else if (exception instanceof Error) {
        try {
            LOG.error("Thread {} threw an error: {}. Shutting down", thread.toString(), exception, exception);
        } catch (Throwable err) {
            // We don't want to not exit because of an issue with logging
        }
        if (exception instanceof OutOfMemoryError) {
            // After catching an OOM java says it is undefined behavior, so don't
            // even try to clean up or we can get stuck on shutdown.
            try {
                System.err.println("Halting due to Out Of Memory Error...");
            } catch (Throwable err) {
                // Again we don't want to exit because of logging issues.
            }
            ExitUtil.halt(EXIT_EXCEPTION_THROWN);
        } else {
            // error other than OutOfMemory
            exit(convertToExitException(exception));
        }
    } else {
        // simple exception in a thread. There's a policy decision here:
        // terminate the service vs. keep going after a thread has failed
        LOG.error("Thread {} threw an exception: {}", thread.toString(), exception, exception);
    }
}

From source file:org.apache.tajo.util.TajoUncaughtExceptionHandler.java

License:Apache License

@Override
public void uncaughtException(Thread t, Throwable e) {
    if (ShutdownHookManager.get().isShutdownInProgress()) {
        LOG.error("Thread " + t + " threw an Throwable, but we are shutting " + "down, so ignoring this", e);
    } else if (e instanceof Error) {
        try {// w w w. j a va2 s . c  o  m
            LOG.fatal("Thread " + t + " threw an Error.", e);
        } catch (Throwable err) {
            //We don't want to not exit because of an issue with logging
        }

        if (e instanceof OutOfMemoryError) {
            //After catching an OOM java says it is undefined behavior, so don't
            //even try to clean up or we can get stuck on shutdown.
            try {
                System.err.println("Halting due to Out Of Memory Error...");
            } catch (Throwable err) {
                //Again we done want to exit because of logging issues.
            }
            ExitUtil.halt(-1);
        } else {
            //ExitUtil.terminate(-1);
        }
    } else {
        LOG.error("Thread " + t + " threw an Exception.", e);
    }
}