Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Use meaningful thread names #1623

Merged
merged 4 commits into from
May 6, 2019
Merged

[Core] Use meaningful thread names #1623

merged 4 commits into from
May 6, 2019

Conversation

kutzi
Copy link
Contributor

@kutzi kutzi commented May 6, 2019

Summary

When running with --threads, give the the pool threads some meaningful names

Details

Before it was using the standard threadfactory, which was naming threads like 'pool-x-thread-y'
Now it is 'cucumber-runner-thread-x'

Motivation and Context

It's better for logging to see which threads belong to cucumber and which are unrelated background threads

@coveralls
Copy link

coveralls commented May 6, 2019

Coverage Status

Coverage increased (+0.02%) to 86.133% when pulling 75c6f0c on executor_names into 940f94b on master.


CucumberThreadFactory() {
SecurityManager s = System.getSecurityManager();
this.group = s != null ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's required nor desirable to manually set the thread group. The ThreadGroup for the workers should be the same as the ThreadGroup of Runtime.run. Currently it is the ThreadGroup of Runtime.Builder.build which need not be the same. Using a different constructor will automatically use the correct ThreadGroup.


@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(this.group, r, "cucumber-runner-thread-" + this.threadNumber.getAndIncrement(), 0L);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the Thread(String name) constructor should be the safest, least confusing option here.

public Thread newThread(Runnable r) {
Thread t = new Thread(this.group, r, "cucumber-runner-thread-" + this.threadNumber.getAndIncrement(), 0L);
if (t.isDaemon()) {
t.setDaemon(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to override the inherited settings?

}

if (t.getPriority() != 5) {
t.setPriority(5);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to override the inherited settings?

Copy link
Contributor

@mpkorstanje mpkorstanje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. But I'm not sure if it's necessary to use all these non-default setting when creating a thread. Could you explain?

@kutzi
Copy link
Contributor Author

kutzi commented May 6, 2019

I just wanted to mirror the behaviour of Executors.defaultThreadFactory() - that's the one which was used effectively before my change - as closely as possible.
See https://github.com/openjdk-mirror/jdk7u-jdk/blob/master/src/share/classes/java/util/concurrent/Executors.java#L572

But I'm also fine with removing some of the none strictly necessary stuff (groups, priority)

@kutzi
Copy link
Contributor Author

kutzi commented May 6, 2019

Actually, we should probably still keep the pool-x prefix, as it is possible to start multiple cucumber Runtimes in the same JVM

@kutzi
Copy link
Contributor Author

kutzi commented May 6, 2019

Maybe cucumber-runner-x-y with x the pool and y the thread?

@mpkorstanje
Copy link
Contributor

I'd say cucumber-runner-x-thread-y for clarity.

@mpkorstanje
Copy link
Contributor

I just wanted to mirror the behaviour of Executors.defaultThreadFactory() - that's the one which was used effectively before my change - as closely as possible.

Ah that makes sense. But it's all behavior we don't quite need. So it's better to keep the code simple.

@mpkorstanje mpkorstanje changed the title Give the cucumber threads some meaningful names [Core] Use meaningful thread names May 6, 2019
@mpkorstanje mpkorstanje merged commit 9ed80b6 into master May 6, 2019
@mpkorstanje mpkorstanje deleted the executor_names branch May 6, 2019 16:25
@mpkorstanje
Copy link
Contributor

Cheers!

@lock
Copy link

lock bot commented May 5, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants