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;
}
}
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);
}
}
}
};
}
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);
}
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-");
}
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-");
}
Aggregations