You can use a custom thread factory, for instance in Ehcache there's one implemented this way:
public class NamedThreadFactory implements ThreadFactory {
private static AtomicInteger threadNumber = new AtomicInteger(1);
private final String namePrefix;
/**
* Constructor accepting the prefix of the threads that will be created by this {@link ThreadFactory}
*
* @param namePrefix
* Prefix for names of threads
*/
public NamedThreadFactory(String namePrefix) {
this.namePrefix = namePrefix;
}
/**
* Returns a new thread using a name as specified by this factory {@inheritDoc}
*/
public Thread newThread(Runnable runnable) {
return new Thread(runnable, namePrefix + " thread-" + threadNumber.getAndIncrement());
}
}
Then you can create your executor this way:
ExecutorService executor = Executors.newFixedThreadPool(currentRecordSize, new NamedThreadFactory("Your prefix here"));