YongGoose opened a new pull request, #7559:
URL: https://github.com/apache/incubator-seata/pull/7559
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Please make sure you have read and understood the contributing
guidelines -->
- [x] I have registered the PR [changes](../changes).
### Ⅰ. Describe what this PR did
### Ⅱ. Does this pull request fix one issue?
<!-- If that, add "fixes #xxx" below in the next line, for example, fixes
#97. -->
fixes #7523
This pull request introduces a mechanism to gracefully shut down
`TableMetaRefreshHolder` threads in the `TableMetaCacheFactory` class and
includes corresponding unit tests to verify the functionality. The changes
improve thread management and ensure proper cleanup of resources.
### Enhancements to Thread Management:
* Added a `shutdown` method in `TableMetaCacheFactory` to terminate all
`TableMetaRefreshHolder` threads and clear the holder map. This ensures proper
cleanup and avoids potential memory leaks.
(`[rm-datasource/src/main/java/org/apache/seata/rm/datasource/sql/struct/TableMetaCacheFactory.javaR111-R123](diffhunk://#diff-30b7b8c98b6422d9e4eef6f7696a208c238cd9fb683415d1982996c37848a99cR111-R123)`)
* Modified the `TableMetaRefreshHolder` class to include a `stopped` flag,
enabling threads to exit gracefully when the `shutdown` method is invoked.
(`[rm-datasource/src/main/java/org/apache/seata/rm/datasource/sql/struct/TableMetaCacheFactory.javaL131-R143](diffhunk://#diff-30b7b8c98b6422d9e4eef6f7696a208c238cd9fb683415d1982996c37848a99cL131-R143)`)
* Implemented the `shutdown` method in `TableMetaRefreshHolder` to stop
thread execution and shut down the thread pool executor if applicable.
(`[rm-datasource/src/main/java/org/apache/seata/rm/datasource/sql/struct/TableMetaCacheFactory.javaR202-R209](diffhunk://#diff-30b7b8c98b6422d9e4eef6f7696a208c238cd9fb683415d1982996c37848a99cR202-R209)`)
### Unit Testing for Shutdown Functionality:
* Added imports and helper methods in `TableMetaCacheFactoryTest` to
facilitate testing of the `shutdown` functionality.
(`[[1]](diffhunk://#diff-77e730cc4f7d04455e5e17eb487f0cc0b012cf0cee5506c405bd499102f8cdbdR20-R21)`,
`[[2]](diffhunk://#diff-77e730cc4f7d04455e5e17eb487f0cc0b012cf0cee5506c405bd499102f8cdbdR31-R33)`)
* Introduced a `shutdownTest` method in `TableMetaCacheFactoryTest` to
verify that `TableMetaRefreshHolder` threads are properly terminated and the
holder map is cleared after invoking `TableMetaCacheFactory.shutdown()`.
(`[rm-datasource/src/test/java/org/apache/seata/rm/datasource/sql/struct/TableMetaCacheFactoryTest.javaR60-R78](diffhunk://#diff-77e730cc4f7d04455e5e17eb487f0cc0b012cf0cee5506c405bd499102f8cdbdR60-R78)`)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]