8
环境 druid-spring-boot-starter:1.2.11 mysql-connector-java:8.0.2 mybatis-plus-boot-starter:3.3.2
配置如下:
` @RestController @Slf4j public class PrintDruidInfoJob { @Autowired private DruidDataSource druidDataSource; @Autowired private GenerateFormulaService generateFormulaService;
ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
/**
* 2s打印一次数据源信息
*/
@PostConstruct
public void init() {
executorService.scheduleAtFixedRate(() -> {
log.info("Druid连接池信息 ---> ConnectCount:" + druidDataSource.getConnectCount() + "\tMaxActive:"
+ druidDataSource.getMaxActive() + "\tMaxWait:" + druidDataSource.getMaxWait() + "\tWaitThreadCount:"
+ druidDataSource.getWaitThreadCount() + "\tActiveConnections:" + druidDataSource.getActiveConnections()
+ "\tNotEmptyWaitThreadCount:" + druidDataSource.getNotEmptyWaitThreadCount());
}, 10, 2, TimeUnit.SECONDS);
}
/**
* 模拟业务代码
*
* @return
*/
@GetMapping(value = "/")
public String test() {
List<Long> stations = Arrays.asList(60110842953808L, 60110842963792L, 60110842920272L, 60110842923088L,
60110842948176L, 60110842839888L, 60110842840912L, 60110842841936L, 60110842530384L, 60110842536784L);
for (Long station : stations) {
new Thread(() -> {
// 这里查询的东西比较多
generateFormulaService.generalFormula(station);
}).start();
}
return "success";
}
} ` 我请求一次该接口,刚开始还能查询到数据,一会就直接阻塞啦, 后续请求该接口,请求都在获取数据库连接时被放到了阻塞队列中,整个过程中也不会释放连接,整个就卡死了,关于DB操作都被阻塞。
如果不用默认的参数,使用自定义参数的话,就能正常执行,不会阻塞啦。不知道这是不是一个bug