Delay Publish
If your services need time to warm up, such as: initialization cache or another reference resources has to be ready. You can use the delay feature to delay publishing services. We fine-tuned the service delay exposure logic in Dubbo 2.6.5, delaying the countdown of services that require delayed exposure until Spring initialization is complete. You won’t be aware of this change while using Dubbo, so please be assured that use.
Notice
Prior to Dubbo-2.6.5Delay five second publish
<dubbo:service delay="5000" />
Delay until Spring initialization is complete before exposing the service
<dubbo:service delay="-1" />
Notice
Dubbo-2.6.5 and laterAll services will be exposed after Spring initialization is complete, and you don’t need to configure delay if you don’t need to delay exposing the service.
Delay five second publish
<dubbo:service delay="5000" />
The initialization deadlock problem of Spring 2.x
Trigger condition
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 thebeanDefinitionMap
, and re-synchronizesingletonObjects
write Bean instance cache.But the
Spring
initialization thread,because need to determine theBean
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.
Avoid ways
- It is highly recommended not to call applicationContext.getBean() in the service implementation class, all using Spring’s beans using IoC injection.
- If you really want to tune getBean(), you can put the configuration of Dubbo Spring final loading.
- If you do not want to rely on the configuration order, you can use
<dubbo:provider delay ="-1"/>
to make Dubbo expose the service after the Spring container has been initialized. - If you use getBean() extensively, the equivalent of degenerating Spring to factory mode is to isolate Dubbo’s service from a separate Spring container.