List of usage examples for java.lang Thread setUncaughtExceptionHandler
public void setUncaughtExceptionHandler(UncaughtExceptionHandler eh)
From source file:fusejext2.JextThreadFactory.java
@Override public synchronized Thread newThread(Runnable r) { final String name = new StringBuilder().append(threadPrefix).append("[").append(count.getAndIncrement()) .append("]").toString(); Thread t = new Thread(r); t.setName(name);//w w w .j a v a2 s . c o m t.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { logger.severe(new StringBuffer().append("Uncaught Exception in thread ").append(name).append("\n") .append(ExceptionUtils.getMessage(e)).append(", ") .append(ExceptionUtils.getRootCauseMessage(e)).append("\n") .append(ExceptionUtils.getFullStackTrace(e)).toString()); logger.severe("Shutting down due to unexpected exception.."); System.exit(23); } }); logger.info("Created new Thread: " + name); return t; }
From source file:org.rhq.metrics.simulator.SimulatorThreadFactory.java
@Override public Thread newThread(Runnable r) { Thread t = new Thread(r, poolName + "-" + threadNumber.getAndIncrement()); t.setDaemon(false);/*from ww w. ja v a2 s . c o m*/ t.setUncaughtExceptionHandler(this); return t; }
From source file:org.thingsplode.agent.monitors.MonitoringExecutor.java
@PostConstruct public void init() { scheduler = Executors.newScheduledThreadPool(schedulerThreadPoolSize, (Runnable r) -> { Thread t = new Thread(r, "SCHEDULER"); t.setDaemon(true);/*w w w . j a va 2 s.c o m*/ t.setUncaughtExceptionHandler((Thread t1, Throwable e) -> { logger.error(String.format("Uncaught exception on thread %s. Exception %s with message %s.", t1.getName(), e.getClass().getSimpleName(), e.getMessage()), e); }); return t; }); if (autoInitializeSystemMetricProvider) { addProvider(new SystemMetricProvider(), 60); } if (autoInitializeThreadMetricProvider) { addProvider(new ThreadMetricProvider(), 300); } scheduleProviders(); }
From source file:be.fgov.kszbcss.rhq.websphere.config.NamedThreadFactory.java
public Thread newThread(final Runnable runnable) { // The log4j MDC is stored in an InheritableThreadLocal. We need to clear it. Runnable runnableWrapper = new Runnable() { public void run() { Hashtable<?, ?> context = MDC.getContext(); if (context != null) { context.clear();/* ww w .j a v a 2 s . c o m*/ } runnable.run(); } }; Thread t = new Thread(group, runnableWrapper, namePrefix + "-" + threadNumber.getAndIncrement()); t.setDaemon(false); t.setUncaughtExceptionHandler(this); return t; }
From source file:com.adaptris.core.jms.MockJmsConnectionErrorHandler.java
@Override public void init() throws CoreException { String loggingId = retrieveConnection(AdaptrisConnection.class).getUniqueId(); if (!isEmpty(loggingId)) { idForLogging = loggingId;/*ww w . jav a 2s . c o m*/ } else { idForLogging = abbreviate(retrieveConnection(JmsConnection.class).getBrokerDetailsForLogging(), 20); } try { String s = "MockJmsConnectionErrorHandler"; final String idForLogging = abbreviate(s, 20); MyExceptionHandler handler = new MyExceptionHandler(); verifier = new MockJmsConnectionVerifier(idForLogging, new CountDownLatch(1)); if (callback != null) { callback.register(verifier); } Thread verifierThread = new Thread(verifier); verifierThread.setUncaughtExceptionHandler(handler); verifierThread.start(); if (additionalLogging()) { log.debug("ActiveJmsConnectionErrorHandler for " + idForLogging + " started"); } } catch (Exception e) { throw new CoreException(e); } }
From source file:org.echocat.jomon.spring.ContextLoadThreadGroup.java
public void addAndStart(@Nonnull Thread thread) { thread.setUncaughtExceptionHandler(this); _threads.add(thread); thread.start(); }
From source file:com.hellblazer.jackal.configuration.PartitionControllerConfig.java
protected ExecutorService controllerDispatchers() { final int id = partitionIdentity.id; return Executors.newCachedThreadPool(new ThreadFactory() { int count = 0; @Override/*w w w . j av a 2 s. co m*/ public Thread newThread(Runnable target) { Thread t = new Thread(target, String.format("Partition Controller Dispatcher[%s]", count++, id)); t.setDaemon(true); t.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { log.error(String.format("Exception on %s", t), e); } }); return t; } }); }
From source file:com.brienwheeler.lib.concurrent.NamedThreadFactory.java
@Override public Thread newThread(Runnable target) { ThreadGroup threadGroup = this.threadGroup.get(); if (threadGroup == null) throw new IllegalStateException( "not allowed to call newThread() before calling setName() on " + getClass().getSimpleName()); log.debug("allocating new thread in " + getName()); Thread thread = new Thread(threadGroup, target, threadGroup.getName() + "-" + threadCount.incrementAndGet()); thread.setUncaughtExceptionHandler(uncaughtExceptionHandler.get()); return thread; }
From source file:com.hellblazer.jackal.configuration.ThreadConfig.java
@Bean(name = "agentDispatchers") @Lazy/*from w w w .j a v a 2s . c o m*/ @Autowired public ExecutorService agentDispatchers(Identity partitionIdentity) { final int id = partitionIdentity.id; return Executors.newCachedThreadPool(new ThreadFactory() { int count = 0; @Override public Thread newThread(Runnable target) { Thread t = new Thread(target, String.format("Agent Dispatcher[%s] for node[%s]", count++, id)); t.setDaemon(true); t.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { log.error(String.format("Exception on %s", t), e); } }); return t; } }); }
From source file:com.hellblazer.jackal.configuration.ThreadConfig.java
@Bean(name = "gossipDispatchers") @Lazy/*from ww w .j a v a2 s . c o m*/ @Autowired public ExecutorService gossipDispatchers(Identity partitionIdentity) { final int id = partitionIdentity.id; return Executors.newCachedThreadPool(new ThreadFactory() { int count = 0; @Override public Thread newThread(Runnable target) { Thread t = new Thread(target, String.format("Gossip Dispatcher[%s] for node[%s]", count++, id)); t.setDaemon(true); t.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { log.error(String.format("Exception on %s", t), e); } }); return t; } }); }