The original code used class-level `BlockingQueue` instances (`queue0`, `queue1`) which caused issues when processing multiple files concurrently. Each comparison needed its *own* dedicated queues to avoid data corruption and incorrect comparisons between different file pairs. This commit creates the `BlockingQueue` instances locally within the file comparison loop.
Additionally, the futures submitted to the executor service were not always being cancelled if an exception occurred or the comparison finished before reaching the end of the files. This could lead to lingering threads. The `finally` block now ensures that both futures are cancelled regardless of how the try block exits, preventing resource leaks and potential deadlocks.
git-svn-id: svn://home0/checkDataIntegrity@3745 71dcc7fd-b1f2-4e5d-bb8e-274146e81173
This commit introduces a significant refactoring of the `Task` class to improve performance and resource utilization when comparing files. Instead of reading directly within the main thread, it now leverages Java's virtual threads and blocking queues to handle file loading concurrently.
Key changes:
- **Virtual Threads:** Uses `ExecutorService` with `newVirtualThreadPerTaskExecutor()` to create lightweight virtual threads for reading from each file. This allows for highly concurrent I/O operations without excessive overhead.
- **Blocking Queues:** Employs `LinkedBlockingQueue` to facilitate communication between the file loading threads and the comparison logic. Each queue holds buffers read from its corresponding file.
- **Buffer Pool:** Continues utilizing the `BufferPool` for managing byte arrays to minimize memory allocation.
- **Loader Method:** A new private method `loader` is introduced to encapsulate the file reading process within each virtual thread, placing read data into the respective queue.
- **Error Handling:** Improved exception handling to properly cancel tasks and propagate exceptions. Interruptions are handled correctly.
These changes should result in significantly improved throughput when comparing large files, especially on systems with multiple cores.
git-svn-id: svn://home0/checkDataIntegrity@3744 71dcc7fd-b1f2-4e5d-bb8e-274146e81173