Skip to content

Commit 9ed80b6

Browse files
kutzimpkorstanje
authored andcommitted
[Core] Use meaningful thread names (#1623)
Before it was using the standard threadfactory, which was naming threads like `pool-x-thread-y`. Now it is `cucumber-runner-y-thread-x`. This better for logging to see which threads belong to cucumber and which are unrelated background
1 parent 940f94b commit 9ed80b6

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

core/src/main/java/cucumber/runtime/Runtime.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
import java.util.concurrent.AbstractExecutorService;
2727
import java.util.concurrent.ExecutorService;
2828
import java.util.concurrent.Executors;
29+
import java.util.concurrent.ThreadFactory;
2930
import java.util.concurrent.TimeUnit;
31+
import java.util.concurrent.atomic.AtomicInteger;
3032

3133
/**
3234
* This is the main entry point for running Cucumber features from the CLI.
@@ -195,7 +197,7 @@ public Runtime build() {
195197
: new SingletonRunnerSupplier(this.runtimeOptions, eventBus, backendSupplier);
196198

197199
final ExecutorService executor = runtimeOptions.isMultiThreaded()
198-
? Executors.newFixedThreadPool(runtimeOptions.getThreads())
200+
? Executors.newFixedThreadPool(runtimeOptions.getThreads(), new CucumberThreadFactory())
199201
: new SameThreadExecutorService();
200202

201203

@@ -210,6 +212,22 @@ public Runtime build() {
210212
}
211213
}
212214

215+
private static final class CucumberThreadFactory implements ThreadFactory {
216+
217+
private static final AtomicInteger poolNumber = new AtomicInteger(1);
218+
private final AtomicInteger threadNumber = new AtomicInteger(1);
219+
private final String namePrefix;
220+
221+
CucumberThreadFactory() {
222+
this.namePrefix = "cucumber-runner-" + poolNumber.getAndIncrement() + "-thread-";
223+
}
224+
225+
@Override
226+
public Thread newThread(Runnable r) {
227+
return new Thread(r, namePrefix + this.threadNumber.getAndIncrement());
228+
}
229+
}
230+
213231
private static final class SameThreadExecutorService extends AbstractExecutorService {
214232

215233
@Override

0 commit comments

Comments
 (0)