com.ryantenney.log4j.NamedThreadFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of redis-appender Show documentation
Show all versions of redis-appender Show documentation
log4j appender for publishing directly to redis
package com.ryantenney.log4j;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
class NamedThreadFactory implements ThreadFactory {
private final String prefix;
private final ThreadFactory threadFactory;
private final AtomicInteger counter = new AtomicInteger();
public NamedThreadFactory(final String prefix) {
this(prefix, Executors.defaultThreadFactory());
}
public NamedThreadFactory(final String prefix, final ThreadFactory threadFactory) {
this.prefix = prefix;
this.threadFactory = threadFactory;
}
@Override
public Thread newThread(Runnable r) {
Thread t = this.threadFactory.newThread(r);
t.setName(this.prefix + "-Thread-" + this.counter.incrementAndGet());
return t;
}
}