หน้าเว็บ

วันเสาร์ที่ 12 กันยายน พ.ศ. 2558

HikariCP Connection Pool

@Configuration
public class DataSourceConfig {

    @Bean
    public HikariDataSource dataSource() {
        HikariConfig config = new HikariConfig();
        config.setDriverClassName("com.mysql.jdbc.Driver");
        config.setJdbcUrl("jdbc:mysql://localhost:3306/spring_boot");
        config.setUsername("root");
        config.setPassword("root");

        config.setMaximumPoolSize(5);
        config.setConnectionTestQuery("SELECT 1");
        config.setPoolName("springHikariCP");

        config.addDataSourceProperty("dataSource.cachePrepStmts", "true");
        config.addDataSourceProperty("dataSource.prepStmtCacheSize", "250");
        config.addDataSourceProperty("dataSource.prepStmtCacheSqlLimit", "2048");
        config.addDataSourceProperty("dataSource.useServerPrepStmts", "true");
        HikariDataSource ds = new HikariDataSource(config);
        return ds;
    }
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น