在并行流中使用JdbcTemplate

问题描述

JdbcTemplate是在SpringBoot中从Spring自动接线的 我如何配置为支持多个线程,例如当它位于parallalStream()中时?调用时是否可以始终创建新连接?

解决方法

JdbcTemplate从数据源获取连接。您可以通过不同的DataSource实现获得不同的行为。

SimpleDriverDataSource 在每次调用时创建新连接。

为获得更好的性能,可以使用连接池数据源。使用连接池,几个连接可以在查询之间重用并并行使用。检出HikariCP或C3PO。

SimpleDriverDataSource

A Simple Guide to Connection Pooling in Java

Configuration Connection Pool in SpringBoot

Connection to a Production Database

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...