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

Remove the use of a FactoryBean when auto-configuring VirtualThreadMetrics #43957

Closed
wants to merge 1 commit into from

Conversation

nosan
Copy link
Contributor

@nosan nosan commented Jan 24, 2025

See gh-43956

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 24, 2025
Copy link
Member

@wilkinsona wilkinsona left a comment

Choose a reason for hiding this comment

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

Wow! That was quick, @nosan. Thanks very much. I've left one comment for your consideration when you have a minute.

Comment on lines 57 to 63
private ClassLoader beanClassLoader;

@Override
public void setBeanClassLoader(ClassLoader classLoader) {
this.beanClassLoader = classLoader;
}

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 we should simplify this further and use the class loader that loaded JvmMetricsAutoConfiguration. Using the bean class loader theoretically allows JvmMetricsAutoConfiguration to be loaded by one class loader and VirtualThreadMetrics to be loaded by another. I don't think we need to support that arrangement as it wouldn't be supported if this were a straightforward @Bean method with VirtualThreadMetrics as its return type.

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, @wilkinsona

I used BeanClassLoader instead of getClass().getClassLoader() because, to my knowledge, it is used in OnClassCondition. I am concerned that if the @ConditionalOnClass check passes but the class is not available in the JvmMetricsAutoConfiguration class loader, it could cause an issue.

But this is probably an impossible situation since @AutoConfiguration classes are loaded using the BeanClassLoader.

PR has been updated.

@nosan
Copy link
Contributor Author

nosan commented Jan 24, 2025

Now, this implementation looks much better than it was before! Thanks very much, @wilkinsona

@mhalbritter mhalbritter self-assigned this Jan 24, 2025
@mhalbritter mhalbritter added type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 24, 2025
@mhalbritter mhalbritter added this to the 3.5.0-M2 milestone Jan 24, 2025
mhalbritter pushed a commit that referenced this pull request Jan 24, 2025
@mhalbritter
Copy link
Contributor

Thanks @nosan !

@nosan
Copy link
Contributor Author

nosan commented Jan 24, 2025

Thanks, @mhalbritter

arefbehboudi pushed a commit to arefbehboudi/spring-boot that referenced this pull request Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: task A general task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants