My multithreaded ———— reads millions Excel data, writes to the database

Source: Internet
Author: User
Question: How to efficiently read millions Excel data to the database?

Problem teardown: 1. How do I read millions Excel data? There is a memory overflow in POI user mode.

2. Where is the read data stored in Excel? 1 million data in memory isn't that a scary thing?

3. How to write data to the database efficiently? How is multithreading used?

Scenario 1:poi command trigger mode to solve the memory overflow problem when reading, the data read into memory, in memory through the Forkjoin tool task disassembly, join to the queue

In-depth thinking: 1 "Every time you have to wait to read the data, in order to do other operations, read itself took 9 seconds time 2" 1 million data is very memory consumption AH

Scenario 2:2 Threads: Thread A and thread B, thread A is responsible for reading the Excel data, thread B is responsible for writing to the database, and how does thread A and thread B work together? Multi-threaded production consumer model

The final core code is attached:

POI Tool Class Code:


The read request uses the POI command mode, and the read is only responsible for adding data to the list, no limit

Core code for production consumption patterns



Use the thread's Factory mode to join the write request to the queue


Queue, constantly fetching write requests, executing


The final execution method of the write request



Warm tip: Database operations can use batch processing


My multithreaded ———— reads millions Excel data, writes to the database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.