refacto: make async persisting logic more readable and maintainable#155
Open
refacto: make async persisting logic more readable and maintainable#155
Conversation
d1ebce7 to
21a74d9
Compare
21a74d9 to
f339863
Compare
jonenst
reviewed
Feb 3, 2026
...java/org/gridsuite/sensitivityanalysis/server/util/SensitivityResultPersistedWriterTest.java
Outdated
Show resolved
Hide resolved
jonenst
reviewed
Feb 3, 2026
src/test/java/org/gridsuite/sensitivityanalysis/server/util/BatchAsyncPollerTest.java
Outdated
Show resolved
Hide resolved
jonenst
reviewed
Feb 3, 2026
src/main/java/org/gridsuite/sensitivityanalysis/server/util/ExecutorProviderService.java
Outdated
Show resolved
Hide resolved
jonenst
reviewed
Feb 5, 2026
src/main/java/org/gridsuite/sensitivityanalysis/server/util/BatchAsyncPoller.java
Outdated
Show resolved
Hide resolved
jonenst
reviewed
Feb 5, 2026
src/main/java/org/gridsuite/sensitivityanalysis/server/util/BatchAsyncPoller.java
Outdated
Show resolved
Hide resolved
93b2b4f to
48a00c7
Compare
871f120 to
2a4ac7a
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors the asynchronous result persistence logic to improve readability and maintainability by replacing manual thread management with ScheduledExecutorService. The refactoring eliminates Thread.sleep() calls and introduces better structured components for batch processing and polling.
Changes:
- Replaced
SensitivityResultWriterPersistedwithSensitivityResultPersistedWriter, refactoring from manual thread management toScheduledExecutorService-based scheduling - Introduced new components:
BatchAsyncPollerfor generic batch polling logic,ExecutorsProviderServicefor thread pool creation, andBatchAsyncPollerFactoryfor poller instantiation - Updated
SensitivityAnalysisWorkerServiceto use the new writer with simplified async completion handling
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/org/gridsuite/sensitivityanalysis/server/util/SensitivityResultPersistedWriter.java | New implementation replacing the old writer, using ScheduledExecutorService and delegating to BatchAsyncPoller instances |
| src/main/java/org/gridsuite/sensitivityanalysis/server/util/BatchAsyncPoller.java | Core component for batch polling and periodic data draining with proper cancellation and completion handling |
| src/main/java/org/gridsuite/sensitivityanalysis/server/util/ExecutorsProviderService.java | Spring service providing configured ScheduledExecutorService instances with custom thread naming |
| src/main/java/org/gridsuite/sensitivityanalysis/server/util/BatchAsyncPollerFactory.java | Factory for creating BatchAsyncPoller instances (should be marked as Spring service) |
| src/main/java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisWorkerService.java | Integrates the new writer with updated async completion and error handling logic |
| src/test/java/org/gridsuite/sensitivityanalysis/server/util/SensitivityResultPersistedWriterTest.java | Unit tests for the new writer implementation |
| src/test/java/org/gridsuite/sensitivityanalysis/server/util/BatchAsyncPollerTest.java | Comprehensive unit tests for the batch poller |
| src/test/java/org/gridsuite/sensitivityanalysis/server/util/ExecutorsProviderServiceTest.java | Unit tests for the executor service provider |
| src/main/java/org/gridsuite/sensitivityanalysis/server/util/SensitivityResultWriterPersisted.java | Deleted - replaced by SensitivityResultPersistedWriter |
| src/test/java/org/gridsuite/sensitivityanalysis/server/util/SensitivityResultWriterPersistedTest.java | Deleted - replaced by SensitivityResultPersistedWriterTest |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
.../java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisWorkerService.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/sensitivityanalysis/server/util/BatchAsyncPoller.java
Outdated
Show resolved
Hide resolved
.../java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisWorkerService.java
Show resolved
Hide resolved
src/test/java/org/gridsuite/sensitivityanalysis/server/util/ScheduledThreadPoolFactoryTest.java
Show resolved
Hide resolved
src/test/java/org/gridsuite/sensitivityanalysis/server/util/BatchAsyncPollerTest.java
Show resolved
Hide resolved
.../java/org/gridsuite/sensitivityanalysis/server/service/SensitivityAnalysisWorkerService.java
Outdated
Show resolved
Hide resolved
...ain/java/org/gridsuite/sensitivityanalysis/server/util/SensitivityResultPersistedWriter.java
Outdated
Show resolved
Hide resolved
...java/org/gridsuite/sensitivityanalysis/server/util/SensitivityResultPersistedWriterTest.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/sensitivityanalysis/server/util/BatchAsyncPoller.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gridsuite/sensitivityanalysis/server/util/BatchAsyncPoller.java
Outdated
Show resolved
Hide resolved
675e804 to
eb786f5
Compare
55cb463 to
6dd76d5
Compare
use a ScheduledExecutorService to handle the background periodic logic safely cancel, wait for completion and close the threads and executor using its api remove Thread::sleep from the code
6dd76d5 to
b1ad449
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



PR Summary
use a ScheduledExecutorService to handle the background periodic logic safely cancel, wait for completion and close the threads and executor using its api
remove Thread::sleep from the code
@jonenst some questions are still remaining, can you provide some background info on the TODOs and FIXME ?