private ExecutorThreadModel(String threadNamePrefix) {
this.threadNamePrefix = threadNamePrefix;
// Create the default filter
defaultFilter = new ExecutorFilter();
ThreadPoolExecutor tpe = (ThreadPoolExecutor) defaultFilter
.getExecutor();
final ThreadFactory originalThreadFactory = tpe.getThreadFactory();
ThreadFactory newThreadFactory = new ThreadFactory() {
private final AtomicInteger threadId = new AtomicInteger(0);
public Thread newThread(Runnable runnable) {
Thread t = originalThreadFactory.newThread(
new NamePreservingRunnable(
runnable,
ExecutorThreadModel.this.threadNamePrefix + '-' +
threadId.incrementAndGet()));
t.setDaemon(true);
return t;
}
};
tpe.setThreadFactory(newThreadFactory);
// Set to default.
setExecutor(null);
}