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

Explain why the thread group is destroyed #1690

Closed

Conversation

stefanbirkner
Copy link
Contributor

@stefanbirkner stefanbirkner commented Jan 2, 2021

This information is currently only available in GitHub. It should be
close to the code so that the reader can understand why we destroy the
thread group.

This information is currently only available in GitHub. It should be
close to the code so that the reader can understand why we destroy the
thread group.
@marcphilipp marcphilipp added this to the 4.13.2 milestone Jan 2, 2021
@@ -121,6 +121,12 @@ public void evaluate() throws Throwable {
CallableStatement callable = new CallableStatement();
FutureTask<Throwable> task = new FutureTask<Throwable>(callable);
ThreadGroup threadGroup = new ThreadGroup("FailOnTimeoutGroup");
// The thread group must be a daemon thread group so that it is
Copy link
Member

Choose a reason for hiding this comment

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

nit: blank line above this line for readability.

@@ -121,6 +121,12 @@ public void evaluate() throws Throwable {
CallableStatement callable = new CallableStatement();
FutureTask<Throwable> task = new FutureTask<Throwable>(callable);
ThreadGroup threadGroup = new ThreadGroup("FailOnTimeoutGroup");
// The thread group must be a daemon thread group so that it is
// destroyed when the time-limiting thread finishes. Only when the
// thread group is destroyed its parent thread group can be destroyed,
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit puzzled by this explanation.

The parent thread group isn't destroyed by any of the code here. The parent thread group will likely live for the life of the thread that ran this Statement, which is likely the life of the test run.

Looking at the original pull, it sounds like ThreadGroupContext is likely java.beans.ThreadGroupContext, and Spring uses that to store data, using the identity hash code of the current ThreadGroup as a key. So I suggest:

"By ensuring the ThreadGroup is destroyed, any data associated with the ThreadGroup (ex: via java.beans.ThreadGroupContext) is destroyed."

Presumably, any tests not using a timeout would have data stored using the ThreadGroup from the main JUnit thread as the key for the context, and that would stay around until all tests complete. Perhaps that isn't a problem because the data doesn't keep growing as more tests are run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for digging deeper into it. #1691 makes this PR obsolete, isn't it?

Copy link
Member

Choose a reason for hiding this comment

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

@stefanbirkner I tried to capture the gist of the comments that you added here in my pull. Please let me know if you want me to say more.

Thanks for the reminder to document why the code does what it does

@stefanbirkner
Copy link
Contributor Author

I'm closing this PR because #1691 is changing the code and adds comments with a better explanation.

@stefanbirkner stefanbirkner deleted the thread-group-not-leaked-2 branch January 3, 2021 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants