All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ryantenney.log4j.NamedThreadFactory Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
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;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy