Skip to content

Altered the example in EmbeddedKafkaHolder usage #3929

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

Merged
merged 1 commit into from
May 28, 2025

Conversation

mipo256
Copy link
Contributor

@mipo256 mipo256 commented May 28, 2025

Integration tests with an EmbeddedKafka instance are sometimes run in parallel in Junit. The current example is not thread safe, so I think the official documentation should account for that.

Integration tests with an EmbeddedKafka instance are sometimes run in parallel in Junit. The current example is not thread safe, so I think the oficial documentation should account for that.

Signed-off-by: mipo256 <[email protected]>
throw new KafkaException("Embedded broker failed to start", e);
}
started = true;
synchronized (this) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is fine. But, don't you think using a lock might be better here since synchronized may have issues with virtual threads?

Copy link
Member

Choose a reason for hiding this comment

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

I think this is fully fine.
Just doc. Plus this is intended only for testing.
There is also a fix in Java 24 for synchronized and pinning from virtual threads: https://openjdk.org/jeps/491

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with @artembilan. The synchronized block no longer pins the OS thread, so I do not think that is an issue

@sobychacko sobychacko added this to the 4.0.0-M3 milestone May 28, 2025
@sobychacko sobychacko merged commit 579e7cb into spring-projects:main May 28, 2025
3 checks passed
spring-builds pushed a commit that referenced this pull request May 28, 2025
Integration tests with an EmbeddedKafka instance are sometimes run in parallel in Junit.
The current example is not thread safe, so I think the oficial documentation should account for that.

Signed-off-by: mipo256 <[email protected]>
(cherry picked from commit 579e7cb)
spring-builds pushed a commit that referenced this pull request May 28, 2025
Integration tests with an EmbeddedKafka instance are sometimes run in parallel in Junit.
The current example is not thread safe, so I think the oficial documentation should account for that.

Signed-off-by: mipo256 <[email protected]>
(cherry picked from commit 579e7cb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants