记一次Mybatis对hive的连接池报错

项目中连接hive查询数据,但是每次重启过后,没有问题,过了几天之后就一直打印error日志。

开启并查看debug日志发现,报错日志显示,当开启sqlSession,第一次写数据之后,会尝试建立数据库connection,但是尝试了所有的数据库名之后(ORACLE,MYSQL,等等),没有找到与之对应的hive,因为hive虽然可以用jdbc的方式连接,但是HIVE这个名字并不在mybatis的xml文件中,导致连接没有建立,到最后提示Broken Pipe,说明连接异常中断

但是由于重启过后的几天内并没有报错,于是猜想问题出在c3p0连接池中,所以添加了自动校验和自动重连。

  • validationQuery - SQL query that can be used by the pool to validate connections before they are returned to the application. If specified, this query MUST be an SQL SELECT statement that returns at least one row.
  • testOnBorrow - true or false: whether a connection should be validated using the validation query each time it is borrowed from the pool. Default: true
  • timeBetweenEvictionRunsMillis - The number of milliseconds between consecutive runs of the evictor. Default: -1 (disabled)
  • numTestsPerEvictionRun - The number of connections that will be checked for idleness by the evictor during each run of the evictor. Default: 3
  • minEvictableIdleTimeMillis - The idle time in milliseconds after which a connection can be removed from the pool by the evictor. Default: 30*60*1000 (30 minutes)
  • testWhileIdle - true or false: whether a connection should be validated by the evictor thread using the validation query while sitting idle in the pool. Default: false

 

testWhileIdle ="true" 开启空闲连接回收器校验”

validationQuery =“hive的验证语句”

timeBetweenEvictionRunsMillis =“30000” 空闲连接30秒检查一次

testOnBorrow =“false” 不然影响性能

参考官网:http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html

 

你可能感兴趣的:(日积月累)