{"record":{"id":"1eebe93bd5b98eee","repo":"alibaba/druid","slug":"keepalivebetweentimemillis-must-be-greater-than-ti","errorCode":null,"errorMessage":"keepAliveBetweenTimeMillis must be greater than timeBetweenEvictionRunsMillis","messagePattern":"keepAliveBetweenTimeMillis must be greater than timeBetweenEvictionRunsMillis","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/com/alibaba/druid/pool/DruidDataSource.java","lineNumber":739,"sourceCode":"\n            if (maxActive < minIdle) {\n                throw new IllegalArgumentException(\"illegal maxActive \" + maxActive);\n            }\n\n            if (getInitialSize() > maxActive) {\n                throw new IllegalArgumentException(\"illegal initialSize \" + this.initialSize + \", maxActive \" + maxActive);\n            }\n\n            if (timeBetweenLogStatsMillis > 0 && useGlobalDataSourceStat) {\n                throw new IllegalArgumentException(\"timeBetweenLogStatsMillis not support useGlobalDataSourceStat=true\");\n            }\n\n            if (maxEvictableIdleTimeMillis < minEvictableIdleTimeMillis) {\n                throw new SQLException(\"maxEvictableIdleTimeMillis must be grater than minEvictableIdleTimeMillis\");\n            }\n\n            if (keepAlive && keepAliveBetweenTimeMillis <= timeBetweenEvictionRunsMillis) {\n                throw new SQLException(\"keepAliveBetweenTimeMillis must be greater than timeBetweenEvictionRunsMillis\");\n            }\n\n            if (this.driverClass != null) {\n                this.driverClass = driverClass.trim();\n            }\n\n            initFromSPIServiceLoader();\n\n            resolveDriver();\n\n            initCheck();\n\n            this.netTimeoutExecutor = new SynchronousExecutor();\n\n            initExceptionSorter();\n            initValidConnectionChecker();\n            validationQueryCheck();\n","sourceCodeStart":721,"sourceCodeEnd":757,"githubUrl":"https://github.com/alibaba/druid/blob/fa8dc9912637a2f729eef9f55356621fec18d40e/core/src/main/java/com/alibaba/druid/pool/DruidDataSource.java#L721-L757","documentation":"SQLException thrown during init() when keepAlive is enabled and keepAliveBetweenTimeMillis <= timeBetweenEvictionRunsMillis. The keepAlive ping is meant to run only on connections idle longer than keepAliveBetweenTimeMillis; if that threshold is not greater than the evictor's run interval, the keepAlive cadence becomes meaningless or harmful, so Druid rejects it.","triggerScenarios":"init() with keepAlive=true and keepAliveBetweenTimeMillis <= timeBetweenEvictionRunsMillis. The check at line 738 throws.","commonSituations":"Enabling keepAlive without raising keepAliveBetweenTimeMillis above the eviction interval; tightening timeBetweenEvictionRunsMillis for aggressive eviction while keepAlive is on; defaults misaligned after enabling keepAlive.","solutions":["Set keepAliveBetweenTimeMillis to a value strictly greater than timeBetweenEvictionRunsMillis (commonly 2x or more).","Confirm units are milliseconds for both.","If you do not need keepAlive, leave keepAlive=false to avoid the constraint entirely."],"exampleFix":"// before\ndataSource.setKeepAlive(true);\ndataSource.setTimeBetweenEvictionRunsMillis(60_000);\ndataSource.setKeepAliveBetweenTimeMillis(60_000); // not greater -> throws\n// after\ndataSource.setKeepAlive(true);\ndataSource.setTimeBetweenEvictionRunsMillis(60_000);\ndataSource.setKeepAliveBetweenTimeMillis(120_000);","handlingStrategy":"validation","validationCode":"if (dataSource.isKeepAlive()\n    && dataSource.getKeepAliveBetweenTimeMillis() <= dataSource.getTimeBetweenEvictionRunsMillis()) {\n    throw new IllegalStateException(\"keepAliveBetweenTimeMillis must be > timeBetweenEvictionRunsMillis\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When enabling keepAlive, set keepAliveBetweenTimeMillis above the eviction interval.","Re-validate timing config after changing either value.","Disable keepAlive if you do not need idle-ping behavior."],"tags":["config","keepalive","eviction","timing","init","validation"],"backgroundTag":null,"analyzedSha":"fa8dc9912637a2f729eef9f55356621fec18d40e","analyzedAt":"2026-08-14T04:55:06.789Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}