docling-java icon indicating copy to clipboard operation
docling-java copied to clipboard

Add support for custom Executor

Open edeandrea opened this issue 2 months ago • 3 comments

Currently all the blocking API methods run on the calling thread, and the async methods run on the fork-join pool. We should allow for passing in (or building the client) with a custom Executor for async operations.

edeandrea avatar Sep 03 '26 12:09 edeandrea

Hi @edeandrea, I'd like to work on this. Proposed design: add asyncExecutor(Executor) to DoclingApiBuilder; the client uses it for every async step (task submission, status polling incl. the delayed re-poll via the 3-arg CompletableFuture.delayedExecutor, and result retrieval). Default stays CompletableFuture's default executor so nothing changes unless it's set, toBuilder() carries it over, and the client never shuts the executor down. One question: since asyncExecutor would be a new abstract method on the builder interface, would you prefer a default method to avoid breaking third-party builders? I have a working branch with WireMock-based tests and can open a PR if this direction works for you.

Naman-Gururani avatar Sep 21 '26 21:09 Naman-Gururani

Hi @edeandrea, I'd like to work on this. Proposed design: add asyncExecutor(Executor) to DoclingApiBuilder; the client uses it for every async step (task submission, status polling incl. the delayed re-poll via the 3-arg CompletableFuture.delayedExecutor, and result retrieval). Default stays CompletableFuture's default executor so nothing changes unless it's set, toBuilder() carries it over, and the client never shuts the executor down. One question: since asyncExecutor would be a new abstract method on the builder interface, would you prefer a default method to avoid breaking third-party builders? I have a working branch with WireMock-based tests and can open a PR if this direction works for you.

Hi @Naman-Gururani thanks for wanting to work on this!

I like the design, adding asyncExecutor to DoclingApiBuilder would be great!

The only change I would might make is defaulting to ForkJoinPool.commonPool() (since that's the default if no pool is supplied).

As to breaking, adding a new method to a builder isn't a breaking change, especially if it defaults to ForkJoinPool.commonPool(). The builder pattern is 100% additive at that point while still allowing for downstream customization.

As for testing, please follow the testing pattern(s) already established in this project (there are wiremock & testcontainers tests).

edeandrea avatar Sep 22 '26 15:09 edeandrea

🎉 This issue has been resolved in v0.7.0 (Release Notes)

docling-java-ops[bot] avatar Oct 05 '26 17:10 docling-java-ops[bot]