Skip to content

LineWriter, NonBlockingLineWriter & various fixes & clean-up#18

Merged
vorburger merged 8 commits into
enola-dev:mainfrom
vorburger:LongIncrementingTask4
Oct 4, 2025
Merged

LineWriter, NonBlockingLineWriter & various fixes & clean-up#18
vorburger merged 8 commits into
enola-dev:mainfrom
vorburger:LongIncrementingTask4

Conversation

@vorburger
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings October 4, 2025 23:45
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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 task execution framework by introducing new LineWriter abstractions for flexible and non-blocking output, and by refactoring the TaskExecutor for improved task lifecycle management and timeout handling. It also includes several clean-ups, documentation updates, and utility class additions to promote best practices for concurrency and logging, particularly in the context of Java's virtual threads.

Highlights

  • New LineWriter Abstractions: Introduced LineWriter interface and LineWriters utility class for flexible output handling, along with NonBlockingLineWriter for asynchronous, non-blocking line output, preventing backpressure and managing overflow.
  • TaskExecutor Refactoring: The TaskExecutor has been refactored to use FutureTask for improved task lifecycle management, including logging task completion and more robust timeout handling via a ScheduledExecutorService. The close() method now gracefully cancels running tasks.
  • Task Documentation and Best Practices: Updated Task Javadoc to provide guidance on using virtual threads, proper interruption handling, and explicitly discouraging the use of Thread.yield() due to its performance implications on modern Java.
  • Utility Class Relocation and Additions: The Threads utility class was moved to a more general dev.enola.common.concurrent package. New utility classes CheckedConsumer (for functional interfaces that can throw checked exceptions) and JulConfigurer (for basic Java Util Logging setup) were added.
  • Demo and Test Updates: The LongIncrementingTask demo was updated to utilize the new NonBlockingLineWriter and JulConfigurer, and Thread.yield() was removed. The SlowTask test was simplified by using the new Threads.sleep utility.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces LineWriter interfaces and NonBlockingLineWriter implementation for asynchronous logging, along with various fixes and improvements to the task execution framework. It includes migration from Thread.sleep to a safer Threads utility and general code cleanup.

  • Adds LineWriter interface and NonBlockingLineWriter for non-blocking output handling
  • Migrates from Thread.sleep to Threads.sleep utility for proper interrupt handling
  • Improves task execution framework with better timeout handling and logging

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/dev/enola/common/log/JulConfigurer.java New utility for configuring Java logging with custom formatter
src/dev/enola/common/function/CheckedConsumer.java New functional interface for consumers that can throw checked exceptions
src/dev/enola/common/concurrent/Threads.java Moved from demo package to common with visibility change
src/dev/enola/be/task/test/SlowTask.java Updated to use Threads.sleep and Duration instead of raw milliseconds
src/dev/enola/be/task/demo/LongIncrementingTask.java Enhanced with NonBlockingLineWriter integration and performance improvements
src/dev/enola/be/task/TaskWithoutInputOutput.java New abstract base class for tasks without input/output
src/dev/enola/be/task/TaskExecutorServices.java Removed unused close method
src/dev/enola/be/task/TaskExecutor.java Improved timeout handling and task lifecycle management
src/dev/enola/be/task/TaskCallable.java Removed duplicate endedAt call
src/dev/enola/be/task/Task.java Enhanced documentation and improved toString output formatting
src/dev/enola/be/io/NonBlockingLineWriter.java New non-blocking line writer implementation with overflow handling
src/dev/enola/be/io/LineWriters.java Utility class with common LineWriter implementations
src/dev/enola/be/io/LineWriter.java New interface for line-based output operations

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

JulConfigurer.configureRootLogger();

// Count to max, with sleep pause between each increment
var max = 1000000L;
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The hardcoded value 1000000L should be extracted to a named constant to improve code readability and maintainability.

Copilot uses AI. Check for mistakes.
while (!Thread.currentThread().isInterrupted()) {
if (overflow) {
// https://en.wikipedia.org/wiki/Ellipsis
delegate.println("[… output ... ※ ... truncated …]");
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The overflow message should be extracted to a named constant to avoid duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
var timeout = task.timeout();
if (!timeout.isZero() && !timeout.isNegative()) {
timeoutScheduler.schedule(
() -> futureTask.cancel(true), timeout.toMillis(), MILLISECONDS);
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timeout cancellation runs asynchronously but there's no handling for potential race conditions if the task completes just as the timeout fires. Consider checking task completion status before cancelling.

Suggested change
() -> futureTask.cancel(true), timeout.toMillis(), MILLISECONDS);
() -> {
if (!futureTask.isDone()) {
futureTask.cancel(true);
}
}, timeout.toMillis(), MILLISECONDS);

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a valuable LineWriter abstraction with a non-blocking implementation, which is excellent for handling task output without blocking. The refactoring of TaskExecutor to improve timeout handling and shutdown logic significantly enhances correctness and robustness. The addition of common utilities like Threads, CheckedConsumer, and JulConfigurer is also a good move. I've identified a critical concurrency bug and a high-severity usability issue in the new NonBlockingLineWriter that should be addressed.

Comment thread src/dev/enola/be/io/NonBlockingLineWriter.java Outdated
Comment thread src/dev/enola/be/io/NonBlockingLineWriter.java
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Copilot AI review requested due to automatic review settings October 4, 2025 23:52
@vorburger vorburger added this pull request to the merge queue Oct 4, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 13 out of 13 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.


var input = new Input(max, sleep);
var task = new LongIncrementingTask(input, System.out::println);
var pumperTask = new NonBlockingLineWriter(13, LineWriters.SYSTEM_OUT);
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic number 13 for queue capacity should be extracted to a named constant or variable to explain its significance and make it configurable.

Copilot uses AI. Check for mistakes.
while (!Thread.currentThread().isInterrupted()) {
if (overflow) {
// https://en.wikipedia.org/wiki/Ellipsis
delegate.println("[… output ... ※ ... truncated …]");
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overflow message contains a mix of different ellipsis characters ('…' and '...'). Consider using consistent ellipsis formatting throughout the message.

Suggested change
delegate.println("[… output ...... truncated …]");
delegate.println("[… output truncated …]");

Copilot uses AI. Check for mistakes.
Merged via the queue into enola-dev:main with commit 659db1d Oct 4, 2025
1 check passed
@vorburger vorburger deleted the LongIncrementingTask4 branch October 4, 2025 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants