简体   繁体   English

Hibernate 和 Spring 连接池默认值

[英]Hibernate and Spring Connection Pool Defaults

I am working on an application which is based on Hibernate 5.1.9.Final and Spring 4.3.6.RELEASE我正在开发一个基于 Hibernate 5.1.9.Final 和 Spring 4.3.6.RELEASE 的应用程序

What I am trying to discover is what the default values for connecting to the relational database are, such as connection_timeout, maxConnections, etc.我试图发现的是连接到关系数据库的默认值是什么,例如 connection_timeout、maxConnections 等。

I am trying to understand this existing project, and I don't have any of this configuration on that, but still, I see several connections on the Database -> Postgres.我试图了解这个现有的项目,但我没有任何这样的配置,但是,我仍然在数据库 -> Postgres 上看到了几个连接。

How to discover what the defaults are?如何发现默认值是什么? Are there defaults values?有默认值吗? And what is the default connection pool framework?什么是默认的连接池框架? C3p0? C3p0?

The default connection pooling mechanisms in hibernate are not production, not even performance testing ready. hibernate 中的默认连接池机制不是生产,甚至没有准备好性能测试。 Here is a quotation from hibernate documentation这是休眠文档的引述

Hibernate's own connection pooling algorithm is, however, quite rudimentary.然而,Hibernate 自己的连接池算法非常初级。 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.只需将 hibernate.connection.pool_size 属性替换为连接池特定设置。 This will turn off Hibernate's internal pool.这将关闭 Hibernate 的内部池。 For example, you might like to use c3p0.例如,您可能喜欢使用 c3p0。

The property setting up the number of pooled connections is:设置池连接数的属性是:

hibernate.connection.pool_size hibernate.connection.pool_size

Here is an example C3P0 configuration:以下是 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

recently Hikari is very popular choice for connection pooling.最近 Hikari 是非常流行的连接池选择。 https://brettwooldridge.github.io/HikariCP/ https://brttwooldridge.github.io/HikariCP/

Here is an example set of Hikari properties:下面是一组 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>

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM