Optimizing Large Excel Import Performance in Java Backend Applications

This article details a step‑by‑step optimization of a Java backend Excel import pipeline, covering migration from POI to EasyExcel, caching database lookups, batch insertion with MySQL VALUES, and parallel processing to reduce a 100k‑row import from minutes to under two minutes.

Top Architect
Top Architect
Top Architect
Optimizing Large Excel Import Performance in Java Backend Applications

In a project requiring import of payment records from Excel, the original implementation using POI and row‑by‑row database queries could only handle a few dozen rows.

To handle 100k+ rows and insert over 300k records, the author iteratively optimized the import process across four versions:

Version 1: POI + manual List<ArrayList> mapping, per‑row validation and insertion, causing massive DB round‑trips.

Version 2: EasyPOI with cached house data in a HashMap via a custom SessionMapper and MyBatis ResultHandler, reducing repeated queries.

Version 3: Switched to Alibaba EasyExcel for faster reading, kept caching and batch insertion.

Version 4: Optimized batch insertion using MySQL values syntax, tuned batch size to 1000 rows, and employed parallel streams with a functional InsertConsumer utility to insert concurrently.

Key code examples include the custom SessionMapper, MapResultHandler, batch insert XML mapper, and the InsertConsumer class that splits a list into sub‑lists of size 1000 and processes them in parallel.

Additional performance tips: avoid excessive logging inside loops, use appropriate thread‑pool size, and prefer faster Excel libraries.

The final result achieved importing 100k rows, 420k arrears records, and related details in about 95 seconds.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaPerformanceMyBatisExcelParallelProcessing
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.