em chào anh, em có một câu hỏi a có thể giải thích giúp em với được không ạ
bài toán của em là dự án e có 2 người code
1 người code sử dụng jpa để kết nối với postgres có sử dụng
spring.datasource.hikari.maximum-pool-size=10
nhưng người 2 sử dụng jdbc và tự tạo một class tạo connection pool riêng như này để lấy ra connection
@Component
public class ConnectionPoolHiraki {
private static HikariDataSource ds;
static void createPool() {
HikariConfig config = new HikariConfig();
config.setDriverClassName("org.postgresql.Driver");
config.setJdbcUrl( "jdbc:postgresql://localhost:5432/postgres" );
config.setUsername("postgres");
config.setPassword("postgres");
config.setMinimumIdle(5);
config.setMaxLifetime(1800000);
config.setMaximumPoolSize(20);
ds = new HikariDataSource( config );
}
public static synchronized Connection getPool() throws SQLException {
if (ds == null) createPool();
return ds.getConnection();
}
}
hoặc nếu không dùng class đó thì em dùng class
@Component
public class PostgresFactory {
@Value("")
private String dataBaseUrl;
@Value("")
private String dataBaseUser;
@Value("")
private String dataBasePassword;
private static PostgresFactory ourInstance;
public static PostgresFactory getInstance() {
if (ourInstance == null) {
synchronized (PostgresFactory .class) {
if (ourInstance == null) {
ourInstance = new PostgresFactory();
}
}
}
return ourInstance;
}
private PostgresFactory() {
}
vậy câu hỏi e muốn hỏi anh thì trường hợp này lên xử lý thế nào ạ, nếu em dùng class ConnectionPoolHiraki thì lại tạo ra
1 pool connection song song với pool đc tạo từ jpa
nhưng nếu sử dụng class PostgresFactory nó lại tạo mới connection đến db mỗi lần vào thì giờ e đang chưa biết lên thống nhất như nào cho ổn nhất ạ