Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
con.prepareStatement 在 MySQL 驱动下,会注册到 ConnectionImpl 的 openStatements 集合里面,除非显式关闭 Statement 或者 Connection,否则Connection会一直保存 Statement 的引用。
因为 DataAccessImpl.getPreparedStatementCreator 里面创建了两次 PreparedStatement,在 tomcat-jdbc 下只会关闭一次,导致每次执行SQL 语句之后 openStatements 都会引用两个 PreparedStatement,但是关闭的时候只关闭了一个,造成内存泄露。
目前只发现 tomcat-jdbc 下有该问题,因为 Spring Boot 默认使用的是 tomcat-jdbc,Rose 集成Spring Boot 之后,不注意的话,常常会出现该问题。