{"record":{"id":"cfde1c51a42a40b6","repo":"alibaba/druid","slug":"timebetweenlogstatsmillis-not-support-useglobaldat","errorCode":null,"errorMessage":"timeBetweenLogStatsMillis not support useGlobalDataSourceStat=true","messagePattern":"timeBetweenLogStatsMillis not support useGlobalDataSourceStat=true","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/com/alibaba/druid/pool/DruidDataSource.java","lineNumber":731,"sourceCode":"                if (cacheServerConfigurationSet) {\n                    this.connectProperties.put(\"cacheServerConfiguration\", \"true\");\n                }\n            }\n\n            if (maxActive <= 0) {\n                throw new IllegalArgumentException(\"illegal maxActive \" + maxActive);\n            }\n\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","sourceCodeStart":713,"sourceCodeEnd":749,"githubUrl":"https://github.com/alibaba/druid/blob/fa8dc9912637a2f729eef9f55356621fec18d40e/core/src/main/java/com/alibaba/druid/pool/DruidDataSource.java#L713-L749","documentation":"IllegalArgumentException thrown during init() when both timeBetweenLogStatsMillis > 0 and useGlobalDataSourceStat=true are set. The stat-logging task (which dumps pool stats periodically) relies on per-datasource stat objects and cannot operate against the shared global stat store, so the combination is forbidden.","triggerScenarios":"init() with timeBetweenLogStatsMillis configured to a positive value AND useGlobalDataSourceStat enabled. The check at line 730 throws.","commonSituations":"Turning on global stat aggregation while also enabling periodic stat logging; carrying both flags over from a template config; metrics integrations that set useGlobalDataSourceStat plus a stats logger.","solutions":["If you want periodic stat logging, set useGlobalDataSourceStat=false (default) and keep timeBetweenLogStatsMillis.","If you need global stats, remove/unset timeBetweenLogStatsMillis and export stats another way.","Pick one: per-datasource stat logging OR global stat aggregation, not both."],"exampleFix":"// before\ndataSource.setUseGlobalDataSourceStat(true);\ndataSource.setTimeBetweenLogStatsMillis(60_000); // throws at init\n// after\ndataSource.setUseGlobalDataSourceStat(false);\ndataSource.setTimeBetweenLogStatsMillis(60_000);","handlingStrategy":"validation","validationCode":"if (dataSource.isUseGlobalDataSourceStat() && dataSource.getTimeBetweenLogStatsMillis() > 0) {\n    throw new IllegalStateException(\"pick one: timeBetweenLogStatsMillis OR useGlobalDataSourceStat, not both\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Decide monitoring strategy up front: per-pool stat logging or global aggregation.","Avoid template configs that enable both flags.","Document the chosen metrics export path in your runbook."],"tags":["config","monitoring","stats","init","validation"],"backgroundTag":null,"analyzedSha":"fa8dc9912637a2f729eef9f55356621fec18d40e","analyzedAt":"2026-08-14T04:55:06.789Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}