--- src/main/java/itn/let/mjo/addr/service/impl/AddrServiceImpl.java
+++ src/main/java/itn/let/mjo/addr/service/impl/AddrServiceImpl.java
... | ... | @@ -6,6 +6,9 @@ |
| 6 | 6 |
import java.util.Date; |
| 7 | 7 |
import java.util.List; |
| 8 | 8 |
import java.util.Locale; |
| 9 |
+import java.util.concurrent.ExecutorService; |
|
| 10 |
+import java.util.concurrent.Executors; |
|
| 11 |
+import java.util.concurrent.TimeUnit; |
|
| 9 | 12 |
import java.util.concurrent.atomic.AtomicInteger; |
| 10 | 13 |
import java.util.regex.Matcher; |
| 11 | 14 |
import java.util.regex.Pattern; |
... | ... | @@ -63,6 +66,7 @@ |
| 63 | 66 |
// private static final int MAX_ADDR_CNT = 500000; |
| 64 | 67 |
//임시 500만개 |
| 65 | 68 |
private static final int MAX_ADDR_CNT = 5000000; |
| 69 |
+ private static final int THREAD_COUNT = 4; // 적절한 스레드 수 설정 |
|
| 66 | 70 |
|
| 67 | 71 |
|
| 68 | 72 |
public List<AddrVO> selectAddrList(AddrVO addrVO) throws Exception {
|
... | ... | @@ -474,7 +478,8 @@ |
| 474 | 478 |
if(addrListVO.size() > 0) {
|
| 475 | 479 |
// 등록 |
| 476 | 480 |
// Batch insert |
| 477 |
- batchInsertAddrList(addrListVO); |
|
| 481 |
+// batchInsertAddrList(addrListVO); |
|
| 482 |
+ batchInsertAddrListAsync(addrListVO); |
|
| 478 | 483 |
|
| 479 | 484 |
// addrDAO.insertAddrList(addrListVO); |
| 480 | 485 |
|
... | ... | @@ -511,27 +516,33 @@ |
| 511 | 516 |
, LocalDateTime.now()); |
| 512 | 517 |
} |
| 513 | 518 |
|
| 514 |
- private void batchInsertAddrList(List<AddrVO> addrListVO) throws Exception {
|
|
| 515 |
- |
|
| 519 |
+ |
|
| 520 |
+ private void batchInsertAddrListAsync(List<AddrVO> addrListVO) throws InterruptedException {
|
|
| 516 | 521 |
int totalSize = addrListVO.size(); |
| 517 | 522 |
int batchCount = (totalSize + BATCH_SIZE - 1) / BATCH_SIZE; |
| 518 |
- long startTime, endTime; |
|
| 519 |
- double executionTime; |
|
| 523 |
+ ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT); |
|
| 520 | 524 |
|
| 521 | 525 |
for (int i = 0; i < batchCount; i++) {
|
| 522 |
- int startIndex = i * BATCH_SIZE; |
|
| 523 |
- int endIndex = Math.min(startIndex + BATCH_SIZE, totalSize); |
|
| 524 |
- List<AddrVO> batchList = addrListVO.subList(startIndex, endIndex); |
|
| 526 |
+ final int startIndex = i * BATCH_SIZE; |
|
| 527 |
+ final int endIndex = Math.min(startIndex + BATCH_SIZE, totalSize); |
|
| 528 |
+ final List<AddrVO> batchList = addrListVO.subList(startIndex, endIndex); |
|
| 525 | 529 |
|
| 526 |
- startTime = System.currentTimeMillis(); |
|
| 527 |
- addrDAO.insertAddrList(batchList); |
|
| 528 |
- endTime = System.currentTimeMillis(); |
|
| 529 |
- |
|
| 530 |
- executionTime = (endTime - startTime) / 1000.0; |
|
| 531 |
- System.out.println("Batch " + (i + 1) + "/" + batchCount + " Execution time: " + executionTime + " seconds");
|
|
| 530 |
+ executor.submit(() -> {
|
|
| 531 |
+ try {
|
|
| 532 |
+ long startTime = System.currentTimeMillis(); |
|
| 533 |
+ addrDAO.insertAddrList(batchList); |
|
| 534 |
+ long endTime = System.currentTimeMillis(); |
|
| 535 |
+ double executionTime = (endTime - startTime) / 1000.0; |
|
| 536 |
+ System.out.println("Batch " + (startIndex / BATCH_SIZE + 1) + "/" + batchCount + " Execution time: " + executionTime + " seconds");
|
|
| 537 |
+ } catch (Exception e) {
|
|
| 538 |
+ e.printStackTrace(); |
|
| 539 |
+ } |
|
| 540 |
+ }); |
|
| 532 | 541 |
} |
| 533 |
- |
|
| 534 |
- } |
|
| 542 |
+ |
|
| 543 |
+ executor.shutdown(); |
|
| 544 |
+ executor.awaitTermination(1, TimeUnit.HOURS); |
|
| 545 |
+ } |
|
| 535 | 546 |
|
| 536 | 547 |
public static boolean isValidPhoneNumber(String phoneNo) {
|
| 537 | 548 |
if (phoneNo == null || phoneNo.isEmpty()) {
|
--- src/main/webapp/WEB-INF/jsp/web/addr/include/addrListforExcel.jsp
+++ src/main/webapp/WEB-INF/jsp/web/addr/include/addrListforExcel.jsp
... | ... | @@ -535,6 +535,7 @@ |
| 535 | 535 |
|
| 536 | 536 |
function excelFileChange(file){
|
| 537 | 537 |
|
| 538 |
+ $('.loading_layer').addClass('active');
|
|
| 538 | 539 |
// var file = event.target.files[0]; |
| 539 | 540 |
if (file) {
|
| 540 | 541 |
var reader = new FileReader(); |
... | ... | @@ -547,6 +548,10 @@ |
| 547 | 548 |
}; |
| 548 | 549 |
reader.readAsArrayBuffer(file); |
| 549 | 550 |
} |
| 551 |
+ |
|
| 552 |
+ //로딩창 hide |
|
| 553 |
+ $('.loading_layer').removeClass('active');
|
|
| 554 |
+ |
|
| 550 | 555 |
} |
| 551 | 556 |
|
| 552 | 557 |
// 엑셀 데이터 처리 함수 |
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?