wcmolin opened a new issue, #18222:
URL: https://github.com/apache/dolphinscheduler/issues/18222

   ### Problem
   
   `JdbcRegistryThreadFactory.getDefaultSchedulerThreadExecutor()` creates a 
new `ScheduledExecutorService` instance on every call. However, `close()` 
invokes the same method to shut down, which closes a freshly created unused 
executor rather than the ones actually running scheduled tasks.
   
   Since the threads are daemon threads and `close()` is only called during 
process shutdown, the JVM terminates all threads on exit, so there is no actual 
thread leak. However, the code logic is inconsistent and could be improved.
   
   ### Analysis
   
   **1. `getDefaultSchedulerThreadExecutor()` is a pure factory method with no 
caching:**
   
   ```java
   // JdbcRegistryThreadFactory.java:29-32
   public static ScheduledExecutorService getDefaultSchedulerThreadExecutor() {
       final String threadNameFormat = 
"ds-jdbc-registry-default-scheduler-thread-%d";
       final int threadSize = Runtime.getRuntime().availableProcessors();
       return ThreadUtils.newDaemonScheduledExecutorService(threadNameFormat, 
threadSize);
   }
   ```
   
   **2. The following call sites each create a separate executor instance for 
scheduled tasks:**
   
   - `JdbcRegistryServer.start()` — purge task
   - `JdbcRegistryServer.start()` — heartbeat refresh
   - `JdbcRegistryDataManager.start()` — data change event detection
   - `JdbcRegistryDataManager.start()` — history event cleanup
   
   **3. `close()` shuts down a new instance instead of the executors running 
the above tasks:**
   
   ```java
   // JdbcRegistry.java - close()
   JdbcRegistryThreadFactory.getDefaultSchedulerThreadExecutor().shutdownNow();
   
   // JdbcRegistryServer.java - close()
   JdbcRegistryThreadFactory.getDefaultSchedulerThreadExecutor().shutdown();
   ```


-- 
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]

Reply via email to