我正在开发一个基于 Hibernate 5.1.9.Final 和 Spring 4.3.6.RELEASE 的应用程序
我试图发现的是连接到关系数据库的默认值是什么,例如connection_timeout、maxConnections等。
我试图了解这个现有项目,我没有任何配置,但我仍然在数据库 -> Postgres 上看到几个连接。
如何发现默认值?有默认值吗?而默认的连接池框架是什么? C3p0?
最佳答案
hibernate 中的默认连接池机制不是生产环境,甚至还没有准备好性能测试。这是来自 hibernate 文档的引用
Hibernate's own connection pooling algorithm is, however, quite rudimentary. It is intended to help you get started and is not intended for use in a production system, or even for performance testing. You should use a third party pool for best performance and stability. Just replace the hibernate.connection.pool_size property with connection pool specific settings. This will turn off Hibernate's internal pool. For example, you might like to use 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
关于java - Hibernate 和 Spring 连接池默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56798399/