spring cloud gateway openfeign 联合使用产生死锁问题,应用启动的时候阻塞卡住。
spring.cloud 版本如下
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2020.0.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
java启动代码
java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
}
##追溯源码发现 boundedElastic-1线程阻塞在getSingleton方法synchronized (this.singletonObjects)锁上

那这时候主线程是否启动应用完成了呢?答案是没有,主线程也在实例化单例bean路上。追溯源码。主线程也在getSingleton方法synchronized (this.singletonObjects)锁上获取bean,boundedElastic-1线程正是主线程发起的,主线程在这里等待返回。boundedElastic-1线程在等待synchronized (this.singletonObjects)锁释放,主线程在getSingleton方法等待boundedElastic-1线程返回结果, 由此死锁产生了。应用启动阻塞卡住了。

##boundedElastic-1线程产生过程,贴几个重要方法
spring event 事件 onApplicationEvent(ApplicationEvent event)
routeLocator.ifAvailable(locator -> locator.getRoutes().blockLast()); blockLast方法是阻塞的。导致此bug主要原因。


##线程名字

##工厂生产线程

