Hikari配置

/**
 * [必填]数据库连接地址
 */
private String jdbcUrl;

/**
 * [必填]数据库连接用户名
 */
private String username;

/**
 * [必填]数据库连接密码
 */
private String password;

/**
 * [必填]数据库连接驱动名称
 */
private String driverClassName;

/**
 * [常用]
 * This property controls the default auto-commit behavior of connections returned from the pool. It is a boolean value. Default: true
 */
private Boolean autoCommit;

/**
 * [常用]当默认30秒在连接池内还没有拿到可用的链接,会报错 1
 * This property controls the maximum number of milliseconds that a client (that's you) will wait for a connection from the pool. If this time is exceeded without a connection becoming available, a SQLException will be thrown. Lowest acceptable connection timeout is 250 ms. Default: 30000 (30 seconds)
 * 此属性控制客户端(即您)等待来自池的连接的最大毫秒数。如果超过此时间而没有可用的连接,则会抛出SQLException。可接受的最低连接超时为250 ms。默认值:30000(30秒)
 * (等待来自池的连接的最大毫秒数)
 */
private Integer connectionTimeout;

/**
 * [常用]允许在池中闲置的最长时间(仅当minimumIdle(默认为10)定义为小于maximumPoolSize(默认10)时,此设置才适用) 1
 * This property controls the maximum amount of time that a connection is allowed to sit idle in the pool. This setting only applies when minimumIdle is defined to be less than maximumPoolSize. Idle connections will not be retired once the pool reaches minimumIdle connections. Whether a connection is retired as idle or not is subject to a maximum variation of +30 seconds, and average variation of +15 seconds. A connection will never be retired as idle before this timeout. A value of 0 means that idle connections are never removed from the pool. The minimum allowed value is 10000ms (10 seconds). Default: 600000 (10 minutes)
 * 此属性控制允许连接在池中保持空闲状态的最长时间。仅当minimumIdle(默认为10)定义为小于maximumPoolSize(默认10)时,此设置才适用。一旦池达到MinimumIdle(默认10)连接,空闲连接将不会退出。连接是否以空闲状态退役,最大变化为+30秒,平均变化为+15秒。在此超时之前,连接永远不会因为闲置而退役。值为0表示永远不会从池中删除空闲连接。最小允许值为10000ms(10秒)。默认值:600000(10分钟)
 * (连接允许在池中闲置的最长时间),依赖minimumIdle<maximumPoolSize>
 *设置minimumIdle(最小空闲连接数)=5,设置最大连接数=10,当空闲=1,当总连接=5,空闲的5个连接将增加10分钟的空闲时间 1
 */
private Integer idleTimeout;

/**
 * [常用]池中连接的最大生存期 1
 * This property controls the maximum lifetime of a connection in the pool. An in-use connection will never be retired, only when it is closed will it then be removed. On a connection-by-connection basis, minor negative attenuation is applied to avoid mass-extinction in the pool. We strongly recommend setting this value, and it should be several seconds shorter than any database or infrastructure imposed connection time limit. A value of 0 indicates no maximum lifetime (infinite lifetime), subject of course to the idleTimeout setting. Default: 1800000 (30 minutes)
 * 此属性控制池中连接的最大生存期。使用中的连接永远不会停止使用,只有在关闭连接后才将其删除。在逐个连接的基础上,应用较小的负衰减以避免池中的质量消灭。我们强烈建议设置此值,它应该比任何数据库或基础结构施加的连接时间限制短几秒钟。值0表示没有最大生存期(无限生存期),当然要遵守idleTimeout(默认10分钟)设置。默认值:1800000(30分钟)
 * 建议设置比数据库超时时长少30秒,参考MySQL wait_timeout参数(show variables like '%timeout%';)默认数据库的wait_timeout(数据库连接闲置最大时间值)参数为8个小时(28800)
 */
private Integer maxLifetime;

/**
 * [常用]
 * if your driver supports JDBC4 we strongly recommend not setting this property. This is for "legacy" drivers that do not support the JDBC4 Connection.isValid() API. This is the query that will be executed just before a connection is given to you from the pool to validate that the connection to the database is still alive. Again, try running the pool without this property, HikariCP will log an error if your driver is not JDBC4 compliant to let you know. Default: none链接有效期检测 sql
 * 如果您的驱动程序支持JDBC4,我们强烈建议不要设置此属性。这是针对不支持JDBC4 Connection.isValid()API的“旧版”驱动程序的。这是将在从池中为您提供连接之前执行的查询,以验证与数据库的连接仍然有效。同样,尝试运行不带该属性的池,如果驱动程序不兼容JDBC4,HikariCP将记录错误。
 */
private String connectionTestQuery;

/**
 * [常用]最小空闲连接数 1
 * his property controls the minimum number of idle connections that HikariCP tries to maintain in the pool. If the idle connections dip below this value and total connections in the pool are less than maximumPoolSize, HikariCP will make a best effort to add additional connections quickly and efficiently. However, for maximum performance and responsiveness to spike demands, we recommend not setting this value and instead allowing HikariCP to act as a fixed size connection pool. Default: same as maximumPoolSize(10)
 * 他的属性控制HikariCP尝试在池中维护的最小空闲连接数。如果空闲连接下降到该值以下,并且池中的总连接数小于maximumPoolSize(10),则HikariCP将尽最大努力快速而有效地添加其他连接。但是,为了获得最佳性能和对峰值需求的响应能力,我们建议不要设置此值,而应让HikariCP充当固定大小的连接池。默认值:与maximumPoolSize(10)相同
 * 此属性控制HikariCP维护的池中最小空闲连接数
 * 默认为10
 * 设置的空闲连接=5设置的总连接数=10,当空闲连接下降到1,总连接数=8,系统会快速补齐空闲连接到5 1
 */
private Integer minimumIdle;

/**
 * [常用]最大连接数 1
 * This property controls the maximum size that the pool is allowed to reach, including both idle and in-use connections. Basically this value will determine the maximum number of actual connections to the database backend. A reasonable value for this is best determined by your execution environment. When the pool reaches this size, and no idle connections are available, calls to getConnection() will block for up to connectionTimeout milliseconds before timing out. Please read about pool sizing. Default: 10
 * 此属性控制允许池达到的最大大小,包括空闲和使用中的连接。基本上,此值将确定到数据库后端的最大实际连接数。合理的值最好由您的执行环境确定。当池达到此大小,并且没有空闲连接可用时,在超时之前,对getConnection()的调用将最多阻塞connectionTimeout(默认30秒)毫秒。请阅读有关池大小的信息。默认值:10
 * 此属性控制允许池到达的最大大小,包括闲置的和使用中的连接。基本上这个值将决定实际连接到数据库后端的最大连接数量。最合适的值由你的执行环境决定。当池达到此大小时,并且没有空闲连接可用,对getConnection()的调用将阻塞最多connectionTimeout毫秒
 * 当连接数=10.等待30秒,将报错 1
 */
private Integer maximumPoolSize;
/**
 * [常用]
 *This property is only available via programmatic configuration or IoC container. This property allows you to specify an instance of a Codahale/Dropwizard MetricRegistry to be used by the pool to record various metrics. See the Metrics wiki page for details. Default: none
 */
private String metricRegistry;
/**
 * [常用]
 *This property is only available via programmatic configuration or IoC container. This property allows you to specify an instance of a Codahale/Dropwizard HealthCheckRegistry to be used by the pool to report current health information. See the Health Checks wiki page for details. Default: none
 */
private String healthCheckRegistry;

/**
 * [常用]连接池名称
 * his property represents a user-defined name for the connection pool and appears mainly in logging and JMX management consoles to identify pools and pool configurations. Default: auto-generated,此属性表示连接池的用户定义名称,主要显示在日志记录和JMX管理控制台中,以标识池和池配置。默认:自动生成
 */
private String poolName;

/**
 * 设置连接被占用的超时时间 1
 * his property controls the amount of time that a connection can be out of the pool before a message is logged indicating a possible connection leak. A value of 0 means leak detection is disabled. Lowest acceptable value for enabling leak detection is 2000 (2 seconds). Default: 0,用来设置连接被占用的超时时间,单位为毫秒,默认为0,表示禁用连接泄露检测。启用泄漏检测的最低可接受值是2000(2秒)
 * 记录一条消息(表明可能发生连接泄漏)之前,连接可以退出池的时间。值为0表示禁用泄漏检测。启用泄漏检测的最低可接受值为2000(2秒)。默认值:0
 * leakDetectionThreshold < SECONDS.toMillis(2) || (leakDetectionThreshold > maxLifetime && maxLifetime > 0) return 0
 * leakDetectionThreshold 小于 2秒 ||(leakDetectionThreshold 大于 maxLifetime(默认30分钟) && maxLifetime>0) return 0
 * leakDetectionThreshold>=2秒 && leakDetectionThreshold<=maxLifetime
 */
private Integer leakDetectionThreshold;
/**
 *是否自定义配置,为true时下面两个参数才生效
 */
private boolean cachePrepStmts;
/**
 *连接池大小默认25,官方推荐250-500
 */
private boolean prepStmtCacheSize;
/**
 *单条语句最大长度默认256,官方推荐2048
 */
private boolean prepStmtCacheSqlLimit;
/**
 *新版本MySQL支持服务器端准备,开启能够得到显著性能提升
 */
private boolean useServerPrepStmts;

/**
 * [不常使用的]
 * This property controls whether the pool will "fail fast" if the pool cannot be seeded with an initial connection successfully. Any positive number is taken to be the number of milliseconds to attempt to acquire an initial connection; the application thread will be blocked during this period. If a connection cannot be acquired before this timeout occurs, an exception will be thrown. This timeout is applied after the connectionTimeout period. If the value is zero (0), HikariCP will attempt to obtain and validate a connection. If a connection is obtained, but fails validation, an exception will be thrown and the pool not started. However, if a connection cannot be obtained, the pool will start, but later efforts to obtain a connection may fail. A value less than zero will bypass any initial connection attempt, and the pool will start immediately while trying to obtain connections in the background. Consequently, later efforts to obtain a connection may fail. Default: 1
 */
public int initializationFailTimeout;

/**
 * [不常使用的]是否隔离内部查询?
 * This property determines whether HikariCP isolates internal pool queries, such as the connection alive test, in their own transaction. Since these are typically read-only queries, it is rarely necessary to encapsulate them in their own transaction. This property only applies if autoCommit is disabled. Default: false
 * 此属性确定HikariCP是否在其自己的事务中隔离内部池查询,例如连接活动测试。由于这些通常是只读查询,因此几乎没有必要将它们封装在自己的事务中。仅当禁用autoCommit(默认true)时,此属性才适用。默认值:false
 */
private Boolean isolateInternalQueries;

/**
 * [不常使用的]是否可以通过JMX暂停和恢复该池?
 * his property controls whether the pool can be suspended and resumed through JMX. This is useful for certain failover automation scenarios. When the pool is suspended, calls to getConnection() will not timeout and will be held until the pool is resumed. Default: false
 * 是否可以通过JMX暂停和恢复该池。这对于某些故障转移自动化方案很有用。当池挂起时,对getConnection()的调用不会超时,并且将保留到恢复池之前。默认值:false
 */
private Boolean allowPoolSuspension;

/**
 * [不常使用的]1
 * This property controls whether Connections obtained from the pool are in read-only mode by default. Note some databases do not support the concept of read-only mode, while others provide query optimizations when the Connection is set to read-only. Whether you need this property or not will depend largely on your application and database. Default: false
 */
private Boolean readOnly;

/**
 * [不常使用的]1
 * This property controls whether or not JMX Management Beans ("MBeans") are registered or not. Default: false
 */
private Boolean registerMbeans;

/**
 * [不常使用的]This property sets the default catalog for databases that support the concept of catalogs. If this property is not specified, the default catalog defined by the JDBC driver is used. Default: driver default
 */
private String catalog;

/**
 * [不常使用的]
 * This property sets a SQL statement that will be executed after every new connection creation before adding it to the pool. If this SQL is not valid or throws an exception, it will be treated as a connection failure and the standard retry logic will be followed. Default: none
 */
private String connectionInitSql;

/**
 * [不常使用的]
 * This property controls the default transaction isolation level of connections returned from the pool. If this property is not specified, the default transaction isolation level defined by the JDBC driver is used. Only use this property if you have specific isolation requirements that are common for all queries. The value of this property is the constant name from the Connection class such as TRANSACTION_READ_COMMITTED, TRANSACTION_REPEATABLE_READ, etc. Default: driver default
 */
private String transactionIsolation;

/**
 * [不常使用的]
 * his property controls the maximum amount of time that a connection will be tested for aliveness. This value must be less than the connectionTimeout. Lowest acceptable validation timeout is 250 ms. Default: 5000
 */
private Integer validationTimeout;

/**
 * [不常使用的]
 * This property is only available via programmatic configuration or IoC container. This property allows you to directly set the instance of the DataSource to be wrapped by the pool, rather than having HikariCP construct it via reflection. This can be useful in some dependency injection frameworks. When this property is specified, the dataSourceClassName property and all DataSource-specific properties will be ignored. Default: none
 */
private String dataSource;
/**
 * [不常使用的]
 * This property sets the default schema for databases that support the concept of schemas. If this property is not specified, the default schema defined by the JDBC driver is used. Default: driver default
 */
private String schema;
/**
 * [不常使用的]
 *This property is only available via programmatic configuration or IoC container. This property allows you to set the instance of the java.util.concurrent.ThreadFactory that will be used for creating all threads used by the pool. It is needed in some restricted execution environments where threads can only be created through a ThreadFactory provided by the application container. Default: none
 */
private String threadFactory;
/**
 * [不常使用的]
 *This property is only available via programmatic configuration or IoC container. This property allows you to set the instance of the java.util.concurrent.ScheduledExecutorService that will be used for various internally scheduled tasks. If supplying HikariCP with a ScheduledThreadPoolExecutor instance, it is recommended that setRemoveOnCancelPolicy(true) is used. Default: none
 */
private String scheduledExecutor;

  

原文地址:https://www.cnblogs.com/alisande/p/14368087.html