Search in sources :

Example 46 with UncaughtExceptionHandler

use of java.lang.Thread.UncaughtExceptionHandler in project gerrit by GerritCodeReview.

the class Daemon method run.

@Override
public int run() throws Exception {
    if (stopOnly) {
        RuntimeShutdown.manualShutdown();
        return 0;
    }
    if (doInit) {
        try {
            new Init(getSitePath()).run();
        } catch (Exception e) {
            throw die("Init failed", e);
        }
    }
    mustHaveValidSite();
    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            log.error("Thread " + t.getName() + " threw exception", e);
        }
    });
    if (runId != null) {
        runFile = getSitePath().resolve("logs").resolve("gerrit.run");
    }
    if (httpd == null) {
        httpd = !slave;
    }
    if (!httpd && !sshd) {
        throw die("No services enabled, nothing to do");
    }
    try {
        start();
        RuntimeShutdown.add(() -> {
            log.info("caught shutdown, cleaning up");
            stop();
        });
        log.info("Gerrit Code Review " + myVersion() + " ready");
        if (runId != null) {
            try {
                Files.write(runFile, (runId + "\n").getBytes(UTF_8));
                runFile.toFile().setReadable(true, false);
            } catch (IOException err) {
                log.warn("Cannot write --run-id to " + runFile, err);
            }
        }
        if (serverStarted != null) {
            serverStarted.run();
        }
        if (inspector) {
            JythonShell shell = new JythonShell();
            shell.set("m", manager);
            shell.set("ds", dbInjector.getInstance(DataSourceProvider.class));
            shell.set("schk", dbInjector.getInstance(SchemaVersionCheck.class));
            shell.set("d", this);
            shell.run();
        } else {
            RuntimeShutdown.waitFor();
        }
        return 0;
    } catch (Throwable err) {
        log.error("Unable to start daemon", err);
        return 1;
    }
}
Also used : SchemaVersionCheck(com.google.gerrit.server.schema.SchemaVersionCheck) DataSourceProvider(com.google.gerrit.server.schema.DataSourceProvider) IOException(java.io.IOException) UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) IOException(java.io.IOException)

Example 47 with UncaughtExceptionHandler

use of java.lang.Thread.UncaughtExceptionHandler in project lucene-solr by apache.

the class RevertDefaultThreadHandlerRule method apply.

@Override
public Statement apply(Statement s, Description d) {
    return new StatementAdapter(s) {

        @Override
        protected void before() throws Throwable {
            if (!applied.getAndSet(true)) {
                UncaughtExceptionHandler p = Thread.getDefaultUncaughtExceptionHandler();
                try {
                    // Try to initialize a zookeeper class that reinitializes default exception handler.
                    Class<?> cl = NIOServerCnxnFactory.class;
                    // Make sure static initializers have been called.
                    Class.forName(cl.getName(), true, cl.getClassLoader());
                } finally {
                    if (p == Thread.getDefaultUncaughtExceptionHandler()) {
                    //  throw new RuntimeException("Zookeeper no longer resets default thread handler.");
                    }
                    Thread.setDefaultUncaughtExceptionHandler(p);
                }
            }
        }
    };
}
Also used : StatementAdapter(com.carrotsearch.randomizedtesting.rules.StatementAdapter) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler)

Example 48 with UncaughtExceptionHandler

use of java.lang.Thread.UncaughtExceptionHandler in project calcite-avatica by apache.

the class KerberosConnection method createRenewalThread.

/**
   * Launches a thread to periodically check the current ticket's lifetime and perform a relogin
   * as necessary.
   *
   * @param originalContext The original login's context.
   * @param originalSubject The original login's subject.
   * @param renewalPeriod The amount of time to sleep inbetween checks to renew
   */
Entry<RenewalTask, Thread> createRenewalThread(LoginContext originalContext, Subject originalSubject, long renewalPeriod) {
    RenewalTask task = new RenewalTask(this, originalContext, originalSubject, jaasConf, renewalPeriod);
    Thread t = new Thread(task);
    // Don't prevent the JVM from existing
    t.setDaemon(true);
    // Log an error message if this thread somehow dies
    t.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread t, Throwable e) {
            LOG.error("Uncaught exception from Kerberos credential renewal thread", e);
        }
    });
    t.setName(RENEWAL_THREAD_NAME);
    return new AbstractMap.SimpleEntry<>(task, t);
}
Also used : UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler)

Example 49 with UncaughtExceptionHandler

use of java.lang.Thread.UncaughtExceptionHandler in project jdk8u_jdk by JetBrains.

the class ForkJoinPool method makeCommonPool.

/**
     * Creates and returns the common pool, respecting user settings
     * specified via system properties.
     */
private static ForkJoinPool makeCommonPool() {
    int parallelism = -1;
    ForkJoinWorkerThreadFactory factory = null;
    UncaughtExceptionHandler handler = null;
    try {
        // ignore exceptions in accessing/parsing properties
        String pp = System.getProperty("java.util.concurrent.ForkJoinPool.common.parallelism");
        String fp = System.getProperty("java.util.concurrent.ForkJoinPool.common.threadFactory");
        String hp = System.getProperty("java.util.concurrent.ForkJoinPool.common.exceptionHandler");
        if (pp != null)
            parallelism = Integer.parseInt(pp);
        if (fp != null)
            factory = ((ForkJoinWorkerThreadFactory) ClassLoader.getSystemClassLoader().loadClass(fp).newInstance());
        if (hp != null)
            handler = ((UncaughtExceptionHandler) ClassLoader.getSystemClassLoader().loadClass(hp).newInstance());
    } catch (Exception ignore) {
    }
    if (factory == null) {
        if (System.getSecurityManager() == null)
            factory = defaultForkJoinWorkerThreadFactory;
        else
            // use security-managed default
            factory = new InnocuousForkJoinWorkerThreadFactory();
    }
    if (// default 1 less than #cores
    parallelism < 0 && (parallelism = Runtime.getRuntime().availableProcessors() - 1) <= 0)
        parallelism = 1;
    if (parallelism > MAX_CAP)
        parallelism = MAX_CAP;
    return new ForkJoinPool(parallelism, factory, handler, LIFO_QUEUE, "ForkJoinPool.commonPool-worker-");
}
Also used : UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 50 with UncaughtExceptionHandler

use of java.lang.Thread.UncaughtExceptionHandler in project voltdb by VoltDB.

the class ForkJoinPool method makeCommonPool.

/**
     * Creates and returns the common pool, respecting user settings
     * specified via system properties.
     */
private static ForkJoinPool makeCommonPool() {
    int parallelism = -1;
    ForkJoinWorkerThreadFactory factory = defaultForkJoinWorkerThreadFactory;
    UncaughtExceptionHandler handler = null;
    try {
        // ignore exceptions in accessing/parsing properties
        String pp = System.getProperty("java.util.concurrent.ForkJoinPool.common.parallelism");
        String fp = System.getProperty("java.util.concurrent.ForkJoinPool.common.threadFactory");
        String hp = System.getProperty("java.util.concurrent.ForkJoinPool.common.exceptionHandler");
        if (pp != null)
            parallelism = Integer.parseInt(pp);
        if (fp != null)
            factory = ((ForkJoinWorkerThreadFactory) ClassLoader.getSystemClassLoader().loadClass(fp).newInstance());
        if (hp != null)
            handler = ((UncaughtExceptionHandler) ClassLoader.getSystemClassLoader().loadClass(hp).newInstance());
    } catch (Exception ignore) {
    }
    if (// default 1 less than #cores
    parallelism < 0 && (parallelism = Runtime.getRuntime().availableProcessors() - 1) < 0)
        parallelism = 0;
    if (parallelism > MAX_CAP)
        parallelism = MAX_CAP;
    return new ForkJoinPool(parallelism, factory, handler, LIFO_QUEUE, "ForkJoinPool.commonPool-worker-");
}
Also used : UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

UncaughtExceptionHandler (java.lang.Thread.UncaughtExceptionHandler)53 Bundle (android.os.Bundle)5 HandlerThread (android.os.HandlerThread)5 IOException (java.io.IOException)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 ThreadFactory (java.util.concurrent.ThreadFactory)4 Test (org.junit.Test)4 LocalLoadingCache (com.google.common.cache.LocalCache.LocalLoadingCache)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Intent (android.content.Intent)1 Message (android.os.Message)1 PowerManager (android.os.PowerManager)1 RemoteException (android.os.RemoteException)1 ConsoleMessage (android.webkit.ConsoleMessage)1 SmartThread (com.alibaba.jstorm.utils.SmartThread)1 JCommander (com.beust.jcommander.JCommander)1 Console (com.beust.jcommander.internal.Console)1