List<PostAddress> postAddressDetails = postAddressDao.getAllList();
if(CollectionUtils.isEmpty(postAddressDetails)){
return ;
}
Set<Long> list =new HashSet<>();
for (PostAddress postAddress : postAddressDetails) {
list.add(postAddress.getCustomer_uid());
}
for (Long uid : list) {
addressCacheService.delete(uid);
}
if (postAddressDetails.size() > 10000) {
betch = 10;
} else if (postAddressDetails.size() > 5000) {
betch = 5;
} else if (postAddressDetails.size() > 1000) {
betch = 3;
}
ExecutorService fixedThreadPool = Executors.newFixedThreadPool(betch);
float num = (float) postAddressDetails.size()/500;
double ceil = Math.ceil(num);
for (int i = 0; i < ceil; i++) {
int startLen = i * 500;
int endLen = ((i + 1) * 500 > postAddressDetails.size() ? postAddressDetails.size() - 1 : (i + 1) * 500);
// 该线程处理
final List<PostAddress> postAddresses = postAddressDetails.subList(startLen, endLen);
fixedThreadPool.execute(new Runnable() {
@Override
public void run() {
for (PostAddress postAddressDetail : postAddresses) {
add(postAddressDetail);
}
}
});
}