开发反馈附件上传报错,附件上传先将附件传到服务器,然后将在数据库中写一条记录。
tomcat报错日志:
20-05-21 11:41:22,267 org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: null
[ERROR] 2020-05-21 11:41:22,267 org.hibernate.util.JDBCExceptionReporter - Connection com.mysql.jdbc.JDBC4Connection@4776d334 is closed.
[ERROR] 2020-05-21 11:41:22,275 org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
从日志上分析数据库连接被关闭了。有两种可能:1.数据库端把连接关闭 2.tomcat把连接回收了。
验证1:询问实施人员,有没有kill过会话,得到回复没有。查看mysql err日志,没有问题。检查mysql参数,超时时间非常长。
验证2:tomcat把连接回收了,检查removeAbandonedTimeout=“180”,3分钟,将文件上传过程打印出时间,发现文件上传之间是需要加密的,整个过程会经常超过180s。再次检查日志,发现加密过程时间长的都会有连接被关闭的错误。
解决方案:临时解决方案是将removeAbandonedTimeout调大。 加密的性能无法提升,只有将加密的过程放到facade外面,避免跟数据库的事务搅在一起。