A small Java tool that renders PDF pages to images (PDFBox) with a custom bounded thread pool, built to turn large PDFs into per-page images fast.
On a ~1000-page document this cut a single-threaded render from ~50 minutes to ~2.5 minutes by parallelising the page-render step across a fixed pool, with back-pressure so memory stays bounded on big files.
Rendering each PDF page is CPU-bound and independent — an ideal parallel
workload, but a naive "one thread per page" blows up memory on a 1000-page file.
MulThreadUtil wraps a fixed-size pool where, once the work queue is full, the
submitting (main) thread runs the task itself — a simple caller-runs
back-pressure that keeps the number of in-flight page buffers bounded instead of
letting a thousand renders pile up at once. Each page's DPI/metadata is detected
(metadata-extractor, commons-imaging) so output resolution is chosen per
document rather than hard-coded.
- PDFBox — page rendering (
PDFRenderer) - metadata-extractor / commons-imaging — image DPI / metadata detection
- Custom fixed thread pool with caller-runs back-pressure (
MulThreadUtil) - Java + Maven
./mvnw clean package
# entry point: com.example.pdfsplit.pdfdeal.TestMulThreadUtil.java— the bounded-pool parallel helper (the core idea)ImageUtils.java— PDF → image rendering + DPI/metadata detectionTimeStatic.java— timing helpers used to measure the speed-up
MIT
Author: Bohea — independent industrial software engineer (Shenzhen). Operator HMIs · device integration · machine data into your customer's ERP. More runnable demos & engineering notes on the site.