提交 19a078bc 编写于 作者: K kohsuke

Adding more probe points to watch out for sudden thread death.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@10156 71c3de6d-444a-0410-be80-ed276b4c234a
上级 ee6ec599
......@@ -16,6 +16,7 @@ import hudson.tasks.Publisher;
import hudson.util.DaemonThreadFactory;
import hudson.util.RemotingDiagnostics;
import hudson.util.RunList;
import hudson.util.ExceptionCatchingThreadFactory;
import java.io.IOException;
import java.io.PrintWriter;
......@@ -386,7 +387,7 @@ public abstract class Computer extends AbstractModelObject implements AccessCont
return RemotingDiagnostics.getThreadDump(getChannel());
}
public static final ExecutorService threadPoolForRemoting = Executors.newCachedThreadPool(new DaemonThreadFactory());
public static final ExecutorService threadPoolForRemoting = Executors.newCachedThreadPool(new ExceptionCatchingThreadFactory(new DaemonThreadFactory()));
//
//
......
......@@ -135,7 +135,8 @@ public class CompressedFile {
* this should be a fairly low-priority task.
*/
private static final ExecutorService compressionThread = new ThreadPoolExecutor(
0, 1, 5L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new DaemonThreadFactory());
0, 1, 5L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(),
new ExceptionCatchingThreadFactory(new DaemonThreadFactory()));
private static final Logger LOGGER = Logger.getLogger(CompressedFile.class.getName());
}
package hudson.util;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.Executors;
import java.util.logging.Logger;
import java.util.logging.Level;
/**
* {@link ThreadFactory} that creates a thread, which in turn displays a stack trace
* when it terminates unexpectedly.
*
* @author Kohsuke Kawaguchi
* @since 1.226
*/
public class ExceptionCatchingThreadFactory implements ThreadFactory, Thread.UncaughtExceptionHandler {
private final ThreadFactory core;
public ExceptionCatchingThreadFactory() {
this(Executors.defaultThreadFactory());
}
public ExceptionCatchingThreadFactory(ThreadFactory core) {
this.core = core;
}
public Thread newThread(Runnable r) {
Thread t = core.newThread(r);
t.setUncaughtExceptionHandler(this);
return t;
}
public void uncaughtException(Thread t, Throwable e) {
LOGGER.log(Level.WARNING, "Thread "+t.getName()+" terminated unexpectedly",e);
}
private static final Logger LOGGER = Logger.getLogger(ExceptionCatchingThreadFactory.class.getName());
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册