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.
Fix Tomcat thread leak warning by using daemon threads
Problem
Password4j creates non-daemon worker threads that cause memory leak warnings in web containers like Tomcat:
Password4jThreadIssue
This occurs because non-daemon threads prevent the web application from unloading cleanly during redeployment or shutdown.
Root Cause
In
Utils.createExecutorService()
, the thread factory explicitly setsthread.setDaemon(false)
, creating non-daemon threads that:Solution
Changed
thread.setDaemon(false)
tothread.setDaemon(true)
in the thread factory withinUtils.createExecutorService()
.Daemon threads:
Changes Made
setDaemon(false)
tosetDaemon(true)
increateExecutorService()
issue163()
test method to verify the fixTesting
The new test
issue163()
verifies that:password4j-worker-*
threads are daemon threadsTest Results
Before fix: Test fails - threads are non-daemon
After fix: Test passes - threads are daemon
Backward Compatibility
This change is fully backward compatible:
Impact
Testing Instructions
mvn test -Dtest=IssuesTest#issue163
Resolves issue #163