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

Improve annotation processing thread-safety #2

Closed
wants to merge 1 commit into from
Closed

Conversation

cbeams
Copy link
Contributor

@cbeams cbeams commented Sep 6, 2011

Commit http://bit.ly/nXumTs ensured that component methods and fields
marked with 'common annotations' such as @resource, @PostConstruct and
@PreDestroy are invoked/assigned once and only once, even if multiple
instances of the CommonAnnotationBeanPostProcessor are processing the
same bean factory.

The implementation works against the InjectionMetadata API, adding and
removing these members from sets that track whether they are already
'externally managed', i.e. that another CABPP has already handled them,
thus avoiding redundant processing.

Prior to this change, the #remove operations against these sets were
not synchronized. In a single-threaded context this is fine thanks to
logic in AbstractAutowireCapableBeanFactory#doCreateBean that checks to
see whether a given bean definition has already been post processed.
However, as reported by SPR-8598, certain cases involving multiple
threads and annotated prototype-scoped beans can cause concurrent
modification exceptions during the #remove operation (ostensibly because
another thread is attempting to do the same removal at the same time,
though this has yet to be reproduced in isolation).

Now the sets originally introduced by the commit above are decorated
with Collections#synchronizedSet and any iterations over those sets
are synchronized properly. This change should have low performance
impact as such processing happens at container startup time (save for
non-singleton lookups at runtime), and there should be little
contention in any case.

Issue: SPR-8598

Commit http://bit.ly/nXumTs ensured that component methods and fields
marked with 'common annotations' such as @resource, @PostConstruct and
@PreDestroy are invoked/assigned once and only once, even if multiple
instances of the CommonAnnotationBeanPostProcessor are processing the
same bean factory.

The implementation works against the InjectionMetadata API, adding and
removing these members from sets that track whether they are already
'externally managed', i.e. that another CABPP has already handled them,
thus avoiding redundant processing.

Prior to this change, the #remove operations against these sets were
not synchronized. In a single-threaded context this is fine thanks to
logic in AbstractAutowireCapableBeanFactory#doCreateBean that checks to
see whether a given bean definition has already been post processed.
However, as reported by SPR-8598, certain cases involving multiple
threads and annotated prototype-scoped beans can cause concurrent
modification exceptions during the #remove operation (ostensibly because
another thread is attempting to do the same removal at the same time,
though this has yet to be reproduced in isolation).

Now the sets originally introduced by the commit above are decorated
with Collections#synchronizedSet and any iterations over those sets
are synchronized properly. This change should have low performance
impact as such processing happens at container startup time (save for
non-singleton lookups at runtime), and there should be little
contention in any case.

Issue: SPR-8598
@cbeams
Copy link
Contributor Author

cbeams commented Sep 12, 2011

Rebased these changes into subversion trunk after review with Juergen.

@cbeams cbeams closed this Sep 12, 2011
bclozel referenced this pull request in bclozel/spring-framework Jun 5, 2014
Solution #2

This commit adds support for Groovy templating, available as of
Groovy 2.3.0 (and 2.3.1 for advanced use cases, such as layouts and
fragments).

To enable this, one should create a new GroovyMarkupViewResolver
and a new GroovyMarkupConfigurer Beans in their application context.

Issue: SPR-11789
bclozel referenced this pull request in bclozel/spring-framework Jun 5, 2014
Solution #2

This commit adds support for Groovy templating, available as of
Groovy 2.3.0 (and 2.3.1 for advanced use cases, such as layouts and
fragments).

To enable this, one should create a new GroovyMarkupViewResolver
and a new GroovyMarkupConfigurer Beans in their application context.

Issue: SPR-11789
lks21c added a commit to lks21c/spring-framework-korean that referenced this pull request Jan 3, 2015
itcrazy0717 added a commit to itcrazy0717/spring-framework that referenced this pull request Jun 6, 2018
#1.对spring源码进行测试,在spring-context模块中添加测试代码
spring-projects#2.对spring的bean生命周期进行调试,具体代码在spring-context模块中
@itcrazy0717 itcrazy0717 mentioned this pull request Jun 6, 2018
This was referenced Jan 10, 2019
This was referenced Jan 11, 2019
drodriguezhdez referenced this pull request in scope-demo/spring-framework Oct 14, 2019
cesarhernandezgt added a commit to cesarhernandezgt/spring-framework that referenced this pull request Mar 28, 2023
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

1 participant