优化批量
This commit is contained in:
+5
-8
@@ -5,13 +5,10 @@ import com.alibaba.excel.write.metadata.WriteSheet;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.util.StopWatch;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
@@ -22,15 +19,15 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
public class BatchTest {
|
||||
|
||||
final int column = 2;
|
||||
final Integer nThreads = 20;
|
||||
|
||||
public static void main(String[] args) throws FileNotFoundException, InterruptedException {
|
||||
BatchTest test = new BatchTest();
|
||||
test.run(args[0], args[1]);
|
||||
test.run(args[0], args[1], args[2], Integer.valueOf(args[3]));
|
||||
}
|
||||
|
||||
public void run(String ip, String file) throws FileNotFoundException, InterruptedException {
|
||||
public void run(String ip, String file, String typeT, Integer nThreads) throws FileNotFoundException, InterruptedException {
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(nThreads);
|
||||
final String type = StringUtils.isEmpty(typeT) ? "1" : typeT;
|
||||
Map<String, List<String>> dataMap = new ConcurrentHashMap<>();
|
||||
AtomicLong count = new AtomicLong(0);
|
||||
String[] headArr = new String[]{"ID", "地址", "省份", "城市", "区域", "乡镇街道", "街道编码", "居委村委", "标准化地址", "是否涉农", "地址验证", "经度", "维度", "百度经度", "百度纬度"};
|
||||
@@ -61,7 +58,7 @@ public class BatchTest {
|
||||
final String address = addressTemp;
|
||||
executorService.submit(() -> {
|
||||
try {
|
||||
String response = restTemplate.getForObject("http://" + ip + "/FangJiaAddressService/fiveDivisionStructure?address={address}&city=江阴市", String.class, address);
|
||||
String response = restTemplate.getForObject("http://" + ip + "/FangJiaAddressService/fiveDivisionStructure?address={address}&city=江阴市&type={type}", String.class, address, type);
|
||||
FangJiaApiResponse<JSONObject> apiResponse = JSONObject.parseObject(response, FangJiaApiResponse.class);
|
||||
if (FangJiaApiResponse.ok().getStatus() == apiResponse.getStatus()) {
|
||||
List<String> addressList = new ArrayList<>();
|
||||
@@ -111,7 +108,7 @@ public class BatchTest {
|
||||
dataMap.put(address, addressList);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("give up");
|
||||
System.out.println("地址" + address + "异常");
|
||||
}
|
||||
} finally {
|
||||
latch.countDown();
|
||||
|
||||
Reference in New Issue
Block a user