nacos托管 proxy druid动态数据源 example提交 - #4045
Conversation
oss-sentinel-ai
left a comment
There was a problem hiding this comment.
Summary
This PR adds a new nacos-druid-example module demonstrating Nacos config management with Druid dynamic datasource. The example is useful for the community, but the code has several issues that should be addressed before merging.
Review Notes
-
[Critical] Resource leak in
DemoControllerconstructor — The constructor callsscheduleTask()10 times in a loop, and each call creates a newScheduledThreadPoolExecutorviaExecutors.newScheduledThreadPool(2). This creates 10 thread pools (20 threads total) that are never shut down. Consider using a single shared executor and managing its lifecycle properly (e.g., implementDisposableBeanor use@PreDestroy). -
[Warning]
System.out.printlnusage — The example usesSystem.out.printlnfor output. Consider using SLF4J logging (LoggerFactory.getLogger(...)) to demonstrate best practices, even in example code. -
[Warning] Constructor doing too much work — The constructor schedules 10 tasks immediately. This is unusual for a Spring controller and may cause issues during application startup. Consider using
@PostConstructorApplicationRunnerinstead. -
[Info] Minor:
123l→123L— InselectTask(),jdbcEntityRepository.findNameById(123l)uses lowercaselwhich can be confused with1. Use uppercaseLfor clarity. -
[Info] Package naming — The package
com.alibaba.demo.nacosdruidexampleis fine, but consider aligning with the existing example package structure (e.g.,com.alibaba.cloud.examples.nacosdruid).
Suggestions
- Fix the resource leak (most important)
- Add proper logging
- Move task scheduling out of the constructor
- Add a README explaining how to run the example and what it demonstrates
Automated review by github-manager-bot
Describe what this PR does / why we need it
Does this pull request fix one issue?
Describe how you did it
Describe how to verify it
Special notes for reviews