Description
ApplicationManager creates a cached thread pool for lifecycle listeners but never shuts it down, causing thread leak when ApplicationManager is destroyed.
Location
platform-core/src/main/java/org/flossware/platform/core/ApplicationManager.java:104-110
this.listenerExecutor =
java.util.concurrent.Executors.newCachedThreadPool(
r -> {
Thread t = new Thread(r, "lifecycle-listener");
t.setDaemon(true);
return t;
});
No shutdown() method calls listenerExecutor.shutdown().
Impact
Severity: LOW-MEDIUM
- Thread Leak: Each ApplicationManager instance creates threads that never terminate
- Resource Leak: Thread pool holds references preventing GC
- Mitigated by Daemon: Threads are daemon so JVM can exit, but still wastes resources
While daemon threads allow JVM exit, the thread pool still:
- Keeps threads alive unnecessarily
- Holds memory and file descriptors
- Shows up in thread dumps as "leaked" resources
Recommendation
- Add shutdown() method to ApplicationManager
- Call listenerExecutor.shutdown() in shutdown()
- Wait for termination with timeout
- Ensure ClusteredApplicationManager.shutdown() calls super.shutdown()
Verification
Looking at ClusteredApplicationManager.shutdown():
@Override
public void shutdown() {
// ... removes cluster listener ...
super.shutdown(); // Good! Calls parent shutdown
}
But ApplicationManager doesn't have a shutdown() method! Need to add it.
Example Fix
// In ApplicationManager class:
public void shutdown() {
LOGGER.info("Shutting down ApplicationManager");
// Shutdown listener executor
listenerExecutor.shutdown();
try {
if (!listenerExecutor.awaitTermination(10, TimeUnit.SECONDS)) {
LOGGER.warn("Listener executor did not terminate, forcing shutdown");
listenerExecutor.shutdownNow();
}
} catch (InterruptedException e) {
listenerExecutor.shutdownNow();
Thread.currentThread().interrupt();
}
// Shutdown other resources...
}
Labels
bug, resource-leak
Description
ApplicationManager creates a cached thread pool for lifecycle listeners but never shuts it down, causing thread leak when ApplicationManager is destroyed.
Location
platform-core/src/main/java/org/flossware/platform/core/ApplicationManager.java:104-110No shutdown() method calls listenerExecutor.shutdown().
Impact
Severity: LOW-MEDIUM
While daemon threads allow JVM exit, the thread pool still:
Recommendation
Verification
Looking at ClusteredApplicationManager.shutdown():
But ApplicationManager doesn't have a shutdown() method! Need to add it.
Example Fix
Labels
bug, resource-leak