주소록 등록 : 쓰레드 4개 추가 - 배치 사이즈 60000개
This commit is contained in:
parent
a806de33b9
commit
97cbc423a9
@ -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<AddrVO> 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<AddrVO> addrListVO) throws Exception {
|
||||
|
||||
|
||||
private void batchInsertAddrListAsync(List<AddrVO> 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<AddrVO> batchList = addrListVO.subList(startIndex, endIndex);
|
||||
final int startIndex = i * BATCH_SIZE;
|
||||
final int endIndex = Math.min(startIndex + BATCH_SIZE, totalSize);
|
||||
final List<AddrVO> 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()) {
|
||||
|
||||
@ -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');
|
||||
|
||||
}
|
||||
|
||||
// 엑셀 데이터 처리 함수
|
||||
|
||||
Loading…
Reference in New Issue
Block a user