休眠和春季连接池默认设置

时间:2019-06-27 20:59:10

标签: java spring postgresql hibernate

我正在开发基于Hibernate 5.1.9.Final和Spring 4.3.6.RELEASE的应用程序

我试图发现的是连接到关系数据库的默认值是什么,例如connection_timeout,maxConnections等。

我正在尝试了解这个现有项目,并且在该项目上没有任何配置,但是仍然可以看到数据库-> Postgres上的多个连接。

如何发现默认值是什么?是否有默认值?以及默认的连接池框架是什么? C3p0?

1 个答案:

答案 0 :(得分:0)

休眠中的默认连接池机制不是生产环境,甚至还没有性能测试就绪。这是休眠文档的报价

  

Hibernate自己的连接池算法相当   基本的。它旨在帮助您入门,而不是   用于生产系统,甚至用于性能   测试。您应该使用第三方池以获得最佳性能,并且   稳定性。只需替换hibernate.connection.pool_size属性   与连接池特定的设置。这将关闭休眠模式   内部池。例如,您可能想使用c3p0。

设置池化连接数的属性是:

hibernate.connection.pool_size

这是C3P0配置示例:

hibernate.connection.driver_class = org.postgresql.Driver
hibernate.connection.url = jdbc:postgresql://localhost/mydatabase
hibernate.connection.username = myuser
hibernate.connection.password = secret
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=1800
hibernate.c3p0.max_statements=50
hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect

最近,Hikari是连接池非常受欢迎的选择。 https://brettwooldridge.github.io/HikariCP/

以下是一组Hikari属性:

<property name="hikari.dataSource.cachePrepStmts">true</property>
  <property name="hikari.dataSource.prepStmtCacheSize">250</property>
  <property name="hikari.dataSource.prepStmtCacheSqlLimit">2048</property>
  <property name="hikari.dataSource.useServerPrepStmts">true</property>
  <property name="hikari.maximumPoolSize">30</property>
  <property name="hikari.idleTimeout">30000</property>

  <!-- Database connection properties -->
  <property name="hibernate.hikari.dataSourceClassName">com.mysql.jdbc.jdbc2.optional.MysqlDataSource</property>
  <property name="hikari.dataSource.url">jdbc:mysql://127.0.0.1/sample</property>
  <property name="hikari.dataSource.user">root</property>
  <property name="hikari.dataSource.password">tiger</property>

来源: https://self-learning-java-tutorial.blogspot.com/2016/01/hibernate-hikaricp-example.html