diff --git a/src/BatchTest.java b/src/BatchTest.java index 7c27ced..fd12d21 100644 --- a/src/BatchTest.java +++ b/src/BatchTest.java @@ -22,33 +22,21 @@ import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicLong; public class BatchTest { - // IP地址 - static final String IP = "192.168.0.100:33080"; - //文件地址 - static final String sourceFilePath = "E:\\goojia\\file\\excel文件\\江阴\\1.xlsx"; static final int column = 2; - //线程数 - static final Integer nThreads = 30; - //涉农类型,1:对私,2:对公 - static final String type = "1"; - - public static void main(String[] args) throws FileNotFoundException, InterruptedException { BatchTest test = new BatchTest(); - test.run(IP, sourceFilePath, nThreads); + test.run(args[0], args[1], args[2], Integer.valueOf(args[3])); } - public void run(String ip, String file, Integer nThreads) throws FileNotFoundException, InterruptedException { + public void run(String ip, String file, String typeT, Integer nThreads) throws FileNotFoundException, InterruptedException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String formattedDate = sdf.format(new Date()); ExecutorService executorService = Executors.newFixedThreadPool(nThreads); + final String type = StringUtils.isEmpty(typeT) ? "1" : typeT; Map> dataMap = new ConcurrentHashMap<>(); AtomicLong count = new AtomicLong(0); -// String[] headArr = new String[]{ -// "ID", "地址", "省份", "省份编码", "城市", "城市编码", "区域", "区域编码", "乡镇街道", "乡镇街道编码", "居委村委", "居委村委编码", "城乡分类编码", -// "城乡分类", "涉农标识", "地址验证", "是否县级市", "是否市辖建制镇", "是否开发区", "开发区名称", "开发区等级", "是否县政府"}; String[] headArr = new String[]{ "ID", "地址", "省份", "城市", "区域", "乡镇街道", "街道编码", "居委村委", "标准化地址", "是否农户地址", "地址验证", "是否县级市", "是否市辖建制镇", "省国家级开发区名称", "开发区等级", "经度", "纬度", "百度经度", "百度纬度"}; List> head = this.formatHead(headArr); @@ -79,7 +67,7 @@ public class BatchTest { final String address = addressTemp; executorService.submit(() -> { try { - String response = restTemplate.getForObject("http://" + IP + "/FangJiaAddressService/fiveDivisionStructure?address={address}&type={type}&city=江阴市", String.class, address, type); + String response = restTemplate.getForObject("http://" + ip + "/FangJiaAddressService/fiveDivisionStructure?address={address}&type={type}&city=江阴市", String.class, address, type); FangJiaApiResponse apiResponse = JSONObject.parseObject(response, FangJiaApiResponse.class); if (FangJiaApiResponse.ok().getStatus() == apiResponse.getStatus()) { List result = new ArrayList<>(); @@ -121,13 +109,6 @@ public class BatchTest { } } catch (Exception ex) { ex.printStackTrace(); -// System.out.println("10ms重试"); - try { - Thread.sleep(1); - System.out.println("地址" + address + "异常"); - } catch (InterruptedException e) { - - } } finally { latch.countDown(); count.incrementAndGet();