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

Performance regression when scheduling is enabled and context contains URL beans [SPR-14666] #19230

Closed
spring-projects-issues opened this issue Sep 3, 2016 · 3 comments
Assignees
Labels
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Sep 3, 2016

Andy Wilkinson opened SPR-14666 and commented

When scheduling is enabled and the context contains URL beans, context refresh becomes very slow. It appears to be due to this change which results in hashCode being called on each bean as a result of the new requiresDestruction method. When the bean is a URL this causes a host name look up, the stack of which is:

java.lang.Thread.State: RUNNABLE
	at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
	at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:907)
	at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1302)
	at java.net.InetAddress.getAllByName0(InetAddress.java:1255)
	at java.net.InetAddress.getAllByName(InetAddress.java:1171)
	at java.net.InetAddress.getAllByName(InetAddress.java:1105)
	at java.net.InetAddress.getByName(InetAddress.java:1055)
	at java.net.URLStreamHandler.getHostAddress(URLStreamHandler.java:436)
	- locked <0x00000007ab7abdf0> (a sun.net.www.protocol.http.Handler)
	at java.net.URLStreamHandler.hashCode(URLStreamHandler.java:353)
	at java.net.URL.hashCode(URL.java:878)
	- locked <0x00000007ab84c240> (a java.net.URL)
	at java.util.AbstractList.hashCode(AbstractList.java:541)
	at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
	at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:964)
	at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.requiresDestruction(ScheduledAnnotationBeanPostProcessor.java:423)
	at org.springframework.beans.factory.support.DisposableBeanAdapter.hasApplicableProcessors(DisposableBeanAdapter.java:431)
	at org.springframework.beans.factory.support.AbstractBeanFactory.requiresDestruction(AbstractBeanFactory.java:1628)
	at org.springframework.beans.factory.support.AbstractBeanFactory.registerDisposableBeanIfNecessary(AbstractBeanFactory.java:1645)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:586)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	- locked <0x000000078135afd0> (a java.util.concurrent.ConcurrentHashMap)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:776)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
	- locked <0x0000000780e56240> (a java.lang.Object)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174)
	at de.malkusch.issue6813.Application.main(Application.java:10)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:483)
	at java.lang.Thread.run(Thread.java:745)

See the referenced Spring Boot issue for more details and for a sample project that reproduces the problem.


Affects: 4.3.2

Reference URL: spring-projects/spring-boot#6813

Issue Links:

  • #17470 @Scheduled methods in @Lazy beans are not scheduled
  • #16830 ScheduledAnnotationBeanPostProcessor should unregister tasks on destruction of individual beans

Referenced from: commits 480cd2c, bd24b97

1 votes, 5 watchers

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 12, 2016

Juergen Hoeller commented

I've revised ScheduledAnnotationBeanPostProcessor to use synchronization against an IdentityHashMap since this is not performance-critical and we only really mean to check against our specific bean instance to begin with. To be backport to 4.3.3 tomorrow.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 15, 2016

Juergen Hoeller commented

Andy Wilkinson, could you double-check this against the latest 4.3.3.BUILD-SNAPSHOT please? I hope it does job... I haven't actually tried the effect with URL beans.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 15, 2016

Andy Wilkinson commented

It does the job. Thanks for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants