If your service need time to warm up.such as:initialization cache,or another reference resources has to be ready.so you can use the delay feature for delay publish service.
<dubbo:service delay="5000" />
<dubbo:service delay="-1" />
The service has already published when
Spring parse the
<dubbo:service /> element,but the
Spring is still initializing other beans.If there is a request coming in, and the service implementation class has a call to
applicationContext.getBean () usage.
Request thread applicationContext.getBean() call, the first synchronization
singletonObjects determine whether the existence of the bean, the synchronization does not exist to initialize the
beanDefinitionMap, and re-synchronize
singletonObjects write Bean instance cache.
Spring initialization thread,because need to determine the
Bean is exist,Directly synchronize beanDefinitionMap to initialize, and synchronize singletonObjects write Bean instance cache.
This will cause the getBean thread to lock the singletonObjects first, then lock the beanDefinitionMap, and lock the singletonObjects again.The Spring initialization thread, the first lock beanDefinitionMap, then lock singletonObjects. Reverse lock thread deadlock, can not provide services, can not start.
<dubbo:provider delay ="-1"/>to make Dubbo expose the service after the Spring container has been initialized.
[^1]: Base on the
ContextRefreshedEvent event of the Spring to trigger publish service.