java.lang.OutOfMemoryError: Java heap space 에러로인한 배치로
@b5b048e55c167406653b95b1469ed10bc0f10688
--- src/main/java/itn/let/mjo/addr/service/impl/AddrServiceImpl.java
+++ src/main/java/itn/let/mjo/addr/service/impl/AddrServiceImpl.java
... | ... | @@ -59,6 +59,7 @@ |
| 59 | 59 |
private static final String PHONE_REGEX = "^(01[016789]-?\\d{3,4}-?\\d{4})$";
|
| 60 | 60 |
private static final Pattern PHONE_PATTERN = Pattern.compile(PHONE_REGEX); |
| 61 | 61 |
private static final Charset EUC_KR = Charset.forName("EUC-KR");
|
| 62 |
+ private static final int BATCH_SIZE = 10000; |
|
| 62 | 63 |
// private static final int MAX_ADDR_CNT = 500000; |
| 63 | 64 |
//임시 500만개 |
| 64 | 65 |
private static final int MAX_ADDR_CNT = 5000000; |
... | ... | @@ -471,7 +472,9 @@ |
| 471 | 472 |
|
| 472 | 473 |
if(addrListVO.size() > 0) {
|
| 473 | 474 |
// 등록 |
| 474 |
- addrDAO.insertAddrList(addrListVO); |
|
| 475 |
+ // Batch insert |
|
| 476 |
+ batchInsertAddrList(addrListVO); |
|
| 477 |
+// addrDAO.insertAddrList(addrListVO); |
|
| 475 | 478 |
|
| 476 | 479 |
} |
| 477 | 480 |
|
... | ... | @@ -497,7 +500,29 @@ |
| 497 | 500 |
, LocalDateTime.now()); |
| 498 | 501 |
} |
| 499 | 502 |
|
| 500 |
- public static boolean isValidPhoneNumber(String phoneNo) {
|
|
| 503 |
+ private void batchInsertAddrList(List<AddrVO> addrListVO) throws Exception {
|
|
| 504 |
+ |
|
| 505 |
+ int totalSize = addrListVO.size(); |
|
| 506 |
+ int batchCount = (totalSize + BATCH_SIZE - 1) / BATCH_SIZE; |
|
| 507 |
+ long startTime, endTime; |
|
| 508 |
+ double executionTime; |
|
| 509 |
+ |
|
| 510 |
+ for (int i = 0; i < batchCount; i++) {
|
|
| 511 |
+ int startIndex = i * BATCH_SIZE; |
|
| 512 |
+ int endIndex = Math.min(startIndex + BATCH_SIZE, totalSize); |
|
| 513 |
+ List<AddrVO> batchList = addrListVO.subList(startIndex, endIndex); |
|
| 514 |
+ |
|
| 515 |
+ startTime = System.currentTimeMillis(); |
|
| 516 |
+ addrDAO.insertAddrList(batchList); |
|
| 517 |
+ endTime = System.currentTimeMillis(); |
|
| 518 |
+ |
|
| 519 |
+ executionTime = (endTime - startTime) / 1000.0; |
|
| 520 |
+ System.out.println("Batch " + (i + 1) + "/" + batchCount + " Execution time: " + executionTime + " seconds");
|
|
| 521 |
+ } |
|
| 522 |
+ |
|
| 523 |
+ } |
|
| 524 |
+ |
|
| 525 |
+ public static boolean isValidPhoneNumber(String phoneNo) {
|
|
| 501 | 526 |
if (phoneNo == null || phoneNo.isEmpty()) {
|
| 502 | 527 |
return false; |
| 503 | 528 |
} |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?