TaskExecutor ScheduledExecutorService etc. cleanup#19
Conversation
Summary of ChangesHello @vorburger, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the TaskExecutor and related concurrent utilities by extracting common functionality into reusable components and adding automated cleanup capabilities. The changes move away from hardcoded implementations toward a more modular and maintainable concurrent utilities framework.
- Extracted
LoggingThreadUncaughtExceptionHandlerinto a standalone utility class with factory method - Created a centralized
Executorsutility class for creating configured executor services with virtual threads - Added automated cleanup scheduling for completed tasks in
TaskExecutorwith configurable eviction intervals
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/dev/enola/common/concurrent/LoggingThreadUncaughtExceptionHandler.java | New utility class for handling uncaught exceptions with logging support |
| src/dev/enola/common/concurrent/Executors.java | New factory class for creating configured executor services with virtual threads |
| src/dev/enola/be/task/TaskExecutorServices.java | Removed - functionality moved to common utilities |
| src/dev/enola/be/task/TaskExecutor.java | Updated to use new utilities and added automated cleanup scheduling |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Code Review
This pull request introduces a cleanup mechanism for completed tasks to prevent memory leaks and refactors executor creation into a new common utility class. The changes are a good improvement, but I've identified a critical bug in the task eviction scheduling logic that could cause incorrect behavior. I've also found some opportunities to improve maintainability by removing code duplication and an obsolete comment.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request is a good refactoring that moves executor service creation to a common utility package and adds a mechanism to clean up completed tasks, addressing a potential memory leak. The changes are generally well-structured. I have identified two high-severity issues: one in TaskExecutor related to the precision of the cleanup interval, which could prevent cleanup from running periodically for sub-second intervals, and another in the new Executors utility class concerning the use of virtual threads for a ScheduledExecutorService, which is an established anti-pattern. I've included specific code suggestions to address these points.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the creation of ExecutorService and ScheduledExecutorService into a new common Executors utility class. It also introduces a mechanism in TaskExecutor to periodically evict completed tasks, preventing a memory leak. The changes are well-structured. My feedback focuses on improving the API of the new Executors utility for better consistency and diagnostics.
|
/gemini review |
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Code Review
This pull request is a nice cleanup and improvement. It refactors the creation of ExecutorServices into a new common utility class dev.enola.common.concurrent.Executors, which improves code organization and reusability. It also introduces a periodic cleanup of completed tasks in TaskExecutor to prevent potential memory leaks, addressing a previous TODO. My review includes a critical fix for the new Executors class and a suggestion to improve the robustness of the new TaskExecutor constructor.
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| cleanupScheduler.close(); | ||
| timeoutScheduler.close(); | ||
| executor.close(); |
There was a problem hiding this comment.
The executor services should be shut down in reverse order of dependency to avoid potential issues. Since the executor might have tasks that could be cancelled by the timeout scheduler, consider closing the executor first, then the timeout scheduler, and finally the cleanup scheduler.
| cleanupScheduler.close(); | |
| timeoutScheduler.close(); | |
| executor.close(); | |
| executor.close(); | |
| timeoutScheduler.close(); | |
| cleanupScheduler.close(); |
| private void evictCompletedTasks() { | ||
| tasks.values().removeIf(task -> task.status().isTerminal()); | ||
| } |
There was a problem hiding this comment.
The evictCompletedTasks method iterates over all tasks to find completed ones. For large task maps, this could be inefficient. Consider maintaining a separate queue of completed tasks or using a time-based eviction strategy that tracks completion timestamps.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| public TaskExecutor(Duration completedTaskEvictionInterval) { | ||
| if (completedTaskEvictionInterval == null) { | ||
| throw new IllegalArgumentException("completedTaskEvictionInterval must not be null"); | ||
| } | ||
| if (completedTaskEvictionInterval.isNegative() || completedTaskEvictionInterval.isZero()) { | ||
| throw new IllegalArgumentException("completedTaskEvictionInterval must be positive"); | ||
| } |
There was a problem hiding this comment.
Consider using Objects.requireNonNull() for the null check on line 47-48 for consistency with the null validation pattern used elsewhere in the codebase.
No description provided.