很久没写过技术类文章,懒了,今天同事分享了一份超时相关问题的解决办法,我记录到博客上,以备日后所需。多谢龚同学的分享。
在做项目中,遇到比较多的超时问题跟大家分享下,具体超时时间设置多少可以根据监控数据、应用容忍和并发线程执行回收的最大等待时间设定。
1、数据库连接超时设置方法
连接池中不能设置超时,如:jndi、dbcp,对于maxwait的设置是表示在连接池满的时候,取新连接时的等待时间,不是jdbc执行的超时时间
1.1 事务级别超时(可以针对某个事务单独设置)
Transaction timeout is a timeout valid in frameworks (Spring, EJB container) or at the application level.
In Spring, you may use XML as shown below or use @Transactional from Java source codes, for configuration.
1.2 statment 超时(ibatis的config文件设置定义范围为全局,如果应用中可以统一设置超时,推荐此方法)
To use iBatis as an example, the default value can be configured by using @defaultStatementTimeout (秒) value insqlMapConfig/settings of sql-map-config.xml. By using @timeout value, you can configure statement, select, insert and update syntax of sql-map.xml separately.
1.3