MyBatis连接池参数

properties = new HashMap<>();

properties.put("driverClassName", "com.mysql.jdbc.Driver");//驱动方式

properties.put("validationQuery", "select 1");//心跳检测语句

properties.put("maxTotal", "30");//最大30

properties.put("minIdle", "2");//最小空闲连接数

properties.put("maxIdle", "10");//最大空闲连接数

properties.put("maxWaitMillis", "10000");//最大等待时间

properties.put("testOnBorrow", "false");//true 表示取连接发送一次心跳检测

properties.put("testOnReturn", "false");//true 表示连接放回连接此发送一次心跳检测

properties.put("testWhileIdle", "false");//true 空闲时候心跳检测

properties.put("removeAbandonedOnBorrow", "false");// true 获取连接时判断当时是否有超时的连接并强制回收放回连接池

properties.put("removeAbandonedOnMaintenance", "true");//ture 空闲是判断当时是否有超时的连接并强制回收放回连接池

properties.put("removeAbandonedTimeout", "30");//连接超时时间

properties.put("logAbandoned", "true");//强制回收连接是否打印日志

properties.put("timeBetweenEvictionRunsMillis", "30000");//空闲心跳检测时间

properties.put("softMinEvictableIdleTimeMillis", "60000");//连接池中连接空闲时长超过该时长则强制关闭连接,单连接小于等于最小空闲连接数则不强制关闭

//properties.put("minEvictableIdleTimeMillis", "60000");//连接池中连接空闲时长超过该时长则强制关闭连接,会全部关闭连接 故一般不设

properties.put("logExpiredConnections", "false");//softMinEvictableIdleTimeMillis该设置触发是否打印日志

properties.put("poolPreparedStatements", "false");//true 缓存jdbc PreparedStatement对象

properties.put("defaultAutoCommit", "false");//默认是否自动提交,每次数据库操作都会提交,注意和enableAutoCommitOnReturn参数的差别

properties.put("enableAutoCommitOnReturn", "true");//true 连接放回连接池的时候提交

properties.put("rollbackOnReturn", "true");//true 放回连接池时候回滚,主要是针对数据库没有commit时候回滚数据

猜你喜欢

转载自my.oschina.net/u/2250817/blog/818352