{"action":"created","issue":{"url":"https://api.github.com/repos/alibaba/druid/issues/870","labels_url":"https://api.github.com/repos/alibaba/druid/issues/870/labels{/name}","comments_url":"https://api.github.com/repos/alibaba/druid/issues/870/comments","events_url":"https://api.github.com/repos/alibaba/druid/issues/870/events","html_url":"https://github.com/alibaba/druid/issues/870","id":87643355,"number":870,"title":"phyTimeout mysql数据库8小时超时问题","user":{"login":"blackshadowwalker","id":5380980,"avatar_url":"https://avatars.githubusercontent.com/u/5380980?v=3","gravatar_id":"","url":"https://api.github.com/users/blackshadowwalker","html_url":"https://github.com/blackshadowwalker","followers_url":"https://api.github.com/users/blackshadowwalker/followers","following_url":"https://api.github.com/users/blackshadowwalker/following{/other_user}","gists_url":"https://api.github.com/users/blackshadowwalker/gists{/gist_id}","starred_url":"https://api.github.com/users/blackshadowwalker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blackshadowwalker/subscriptions","organizations_url":"https://api.github.com/users/blackshadowwalker/orgs","repos_url":"https://api.github.com/users/blackshadowwalker/repos","events_url":"https://api.github.com/users/blackshadowwalker/events{/privacy}","received_events_url":"https://api.github.com/users/blackshadowwalker/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-06-12T07:43:37Z","updated_at":"2015-06-16T03:02:18Z","closed_at":null,"body":"增加一个参数：phyTimeoutMillis = 5 * 3600 * 1000  物理连接的超时时间，\r\n如果池中的一个物理连接超过指定的时间（默认5小时）则关闭物理连接，以避免mysql数据库8小时超时的限制而报异常，在DestroyTask线程中处理\r\n````java\r\nint phytimeoutms = currentTimeMillis - com.alibaba.druid.proxy.jdbc.ConnectionProxy.getConnectedTime();\r\nif( phytimeoutms  >= phyTimeoutMillis  ){\r\n   JdbcUtils.close(connection);\r\n}\r\n````"},"comment":{"url":"https://api.github.com/repos/alibaba/druid/issues/comments/112267164","html_url":"https://github.com/alibaba/druid/issues/870#issuecomment-112267164","issue_url":"https://api.github.com/repos/alibaba/druid/issues/870","id":112267164,"user":{"login":"blackshadowwalker","id":5380980,"avatar_url":"https://avatars.githubusercontent.com/u/5380980?v=3","gravatar_id":"","url":"https://api.github.com/users/blackshadowwalker","html_url":"https://github.com/blackshadowwalker","followers_url":"https://api.github.com/users/blackshadowwalker/followers","following_url":"https://api.github.com/users/blackshadowwalker/following{/other_user}","gists_url":"https://api.github.com/users/blackshadowwalker/gists{/gist_id}","starred_url":"https://api.github.com/users/blackshadowwalker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blackshadowwalker/subscriptions","organizations_url":"https://api.github.com/users/blackshadowwalker/orgs","repos_url":"https://api.github.com/users/blackshadowwalker/repos","events_url":"https://api.github.com/users/blackshadowwalker/events{/privacy}","received_events_url":"https://api.github.com/users/blackshadowwalker/received_events","type":"User","site_admin":false},"created_at":"2015-06-16T03:02:18Z","updated_at":"2015-06-16T03:02:18Z","body":"虽然druid会在进行逻辑打开连接时如果空闲达到一定的时间就检查连接的有效性，如果存在以下这种情况就会达到mysql默认8小时空闲超时：\r\n1. 连接池minIdle >=1 , 这某个连接一直未被逻辑打开，这些被保留的连接一直未被使用\r\n2. (testOnBorrow=false， testWhileIdle=true, testOnReturn=false)连接池中的连接很活跃（空闲时间小于timeBetweenEvictionRunsMillis），但是池中获取连接后并未进行任何的数据库操作，从而未进行与数据库的真实通讯，这样会导致大量的连接空闲超时"}}