From 97cbc423a9e2b114d448137f0ac4a5e3aeba9486 Mon Sep 17 00:00:00 2001 From: hylee Date: Mon, 29 Jul 2024 17:46:30 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A3=BC=EC=86=8C=EB=A1=9D=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D=20:=20=EC=93=B0=EB=A0=88=EB=93=9C=204=EA=B0=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20-=20=EB=B0=B0=EC=B9=98=20=EC=82=AC?= =?UTF-8?q?=EC=9D=B4=EC=A6=88=2060000=EA=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../addr/service/impl/AddrServiceImpl.java | 43 ++++++++++++------- .../jsp/web/addr/include/addrListforExcel.jsp | 5 +++ 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/main/java/itn/let/mjo/addr/service/impl/AddrServiceImpl.java b/src/main/java/itn/let/mjo/addr/service/impl/AddrServiceImpl.java index 489c2862..7a6a3d3a 100644 --- a/src/main/java/itn/let/mjo/addr/service/impl/AddrServiceImpl.java +++ b/src/main/java/itn/let/mjo/addr/service/impl/AddrServiceImpl.java @@ -6,6 +6,9 @@ import java.time.LocalDateTime; import java.util.Date; import java.util.List; import java.util.Locale; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -63,6 +66,7 @@ public class AddrServiceImpl extends EgovAbstractServiceImpl implements AddrSer // private static final int MAX_ADDR_CNT = 500000; //임시 500만개 private static final int MAX_ADDR_CNT = 5000000; + private static final int THREAD_COUNT = 4; // 적절한 스레드 수 설정 public List selectAddrList(AddrVO addrVO) throws Exception { @@ -474,7 +478,8 @@ public class AddrServiceImpl extends EgovAbstractServiceImpl implements AddrSer if(addrListVO.size() > 0) { // 등록 // Batch insert - batchInsertAddrList(addrListVO); +// batchInsertAddrList(addrListVO); + batchInsertAddrListAsync(addrListVO); // addrDAO.insertAddrList(addrListVO); @@ -511,27 +516,33 @@ public class AddrServiceImpl extends EgovAbstractServiceImpl implements AddrSer , LocalDateTime.now()); } - private void batchInsertAddrList(List addrListVO) throws Exception { - + + private void batchInsertAddrListAsync(List addrListVO) throws InterruptedException { int totalSize = addrListVO.size(); int batchCount = (totalSize + BATCH_SIZE - 1) / BATCH_SIZE; - long startTime, endTime; - double executionTime; + ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT); for (int i = 0; i < batchCount; i++) { - int startIndex = i * BATCH_SIZE; - int endIndex = Math.min(startIndex + BATCH_SIZE, totalSize); - List batchList = addrListVO.subList(startIndex, endIndex); + final int startIndex = i * BATCH_SIZE; + final int endIndex = Math.min(startIndex + BATCH_SIZE, totalSize); + final List batchList = addrListVO.subList(startIndex, endIndex); - startTime = System.currentTimeMillis(); - addrDAO.insertAddrList(batchList); - endTime = System.currentTimeMillis(); - - executionTime = (endTime - startTime) / 1000.0; - System.out.println("Batch " + (i + 1) + "/" + batchCount + " Execution time: " + executionTime + " seconds"); + executor.submit(() -> { + try { + long startTime = System.currentTimeMillis(); + addrDAO.insertAddrList(batchList); + long endTime = System.currentTimeMillis(); + double executionTime = (endTime - startTime) / 1000.0; + System.out.println("Batch " + (startIndex / BATCH_SIZE + 1) + "/" + batchCount + " Execution time: " + executionTime + " seconds"); + } catch (Exception e) { + e.printStackTrace(); + } + }); } - - } + + executor.shutdown(); + executor.awaitTermination(1, TimeUnit.HOURS); + } public static boolean isValidPhoneNumber(String phoneNo) { if (phoneNo == null || phoneNo.isEmpty()) { diff --git a/src/main/webapp/WEB-INF/jsp/web/addr/include/addrListforExcel.jsp b/src/main/webapp/WEB-INF/jsp/web/addr/include/addrListforExcel.jsp index 0fb6dfe3..788201ed 100644 --- a/src/main/webapp/WEB-INF/jsp/web/addr/include/addrListforExcel.jsp +++ b/src/main/webapp/WEB-INF/jsp/web/addr/include/addrListforExcel.jsp @@ -535,6 +535,7 @@ $(document).on('drop', function (e){ function excelFileChange(file){ + $('.loading_layer').addClass('active'); // var file = event.target.files[0]; if (file) { var reader = new FileReader(); @@ -547,6 +548,10 @@ $(document).on('drop', function (e){ }; reader.readAsArrayBuffer(file); } + + //로딩창 hide + $('.loading_layer').removeClass('active'); + } // 엑셀 데이터 처리 함수