When I initiate a remote call for initialization using a Feign API in the main thread, and perform similar operations using the same Feign API in an asynchronous thread in the initialization of another class.
I am following org.springframework.cloud.context.named.NamedContextFactory#getContext obtains the lock, there will be a call to the context.refresh(), which in turn will contain another lock. At certain times, due to uncontrollable sequence, the main thread may experience a deadlock and fail to start.
Sample
@Component
Class A {
@PostConstruct
public void init() {
// Feign Api remote call
}
}
@Component
Class B {
@PostConstruct
public void init() {
Executors.newSingleThreadExecutor().execute(() -> {
// Same feign API calls
});
}
}
When I initiate a remote call for initialization using a
Feign API
in the main thread, and perform similar operations using the same Feign API in an asynchronous thread in the initialization of another class. I am followingorg.springframework.cloud.context.named.NamedContextFactory#getContext
obtains the lock, there will be a call to thecontext.refresh()
, which in turn will contain another lock. At certain times, due to uncontrollable sequence, the main thread may experience a deadlock and fail to start.Sample