Problem: The system requires importing 400,000 Excel data, and the server has a memory overflow using the poi method.
Solution: Because HSSFWorkbook workbook = new HSSFWorkbook(path) loads excel into memory at one time, resulting in insufficient memory.
Therefore, the read csv format is adopted. Since the data of csv is formed in x1, x2, x3, it is similar to reading the txt document.
private BufferedReader bReader; /** * Execution file entry*/ public void execute() { try { if(!path.endsWith(".csv")){ logger.info("-----This file is not a CSV file, please upload the correct file format-------"); return ; } Long startTime = System.currentTimeMillis(); logger.info("------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ endTime + "---Time consumes time=" + (endTime - startTime)); } catch (Exception e) { e.printStackTrace(); } } /** * Read csv and process data* @param path * @throws Exception */ private void readCSV(String path) throws Exception { File file = new File(path); try { bReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "gbk")); String line = ""; //Ignore the first line title for (int i = 0; i < 1; i++) { line = bReader.readLine(); } while((line = bReader.readLine()) != null){ if (line.trim() != "") { //The split is the corresponding cell, pay attention to the empty situation String[] result = line.split(","); } } } } finally { if (bReader != null) { bReader.close(); } } } } }The above article solves the problem of memory overflow in large amounts of data imported from Java to Excel is all the content I share with you. I hope it can give you a reference and I hope you can support Wulin.com more.