多线程降低

This commit is contained in:
2025-02-20 13:46:01 +08:00
parent b1819a6470
commit b519a64b9c
2 changed files with 23 additions and 9 deletions
@@ -36,7 +36,7 @@ class TownStandardBatch extends BaseBatch{
def fullCityMap = CommonDatautils.queryFullNameCity() def fullCityMap = CommonDatautils.queryFullNameCity()
def regionMap = com.fangjia.script.commData.CommonDatautils.queryAllRegionNameByCity() def regionMap = com.fangjia.script.commData.CommonDatautils.queryAllRegionNameByCity()
def regionFullNameMap = com.fangjia.script.commData.CommonDatautils.queryAllRegionFullNameByCity() def regionFullNameMap = com.fangjia.script.commData.CommonDatautils.queryAllRegionFullNameByCity()
public static ExecutorService fixedThreadPool = Executors.newFixedThreadPool(100) public static ExecutorService fixedThreadPool = Executors.newFixedThreadPool(20)
def updateList = [] def updateList = []
def addAliasList = [] def addAliasList = []
@@ -12,6 +12,7 @@ import org.jsoup.Jsoup
import java.util.zip.GZIPInputStream import java.util.zip.GZIPInputStream
class GaoDeApiUtils { class GaoDeApiUtils {
//94c74c60e102972a8d17b7b75d7403be
def static GAO_DE_AK = "94c74c60e102972a8d17b7b75d7403be" //宝剑:c6fcd4bfbc40d73ee762b8115dca3390 def static GAO_DE_AK = "94c74c60e102972a8d17b7b75d7403be" //宝剑:c6fcd4bfbc40d73ee762b8115dca3390
//15021384995:dfc2245bac8a7b2d5b62e060e59d4eca //15021384995:dfc2245bac8a7b2d5b62e060e59d4eca
@@ -29,15 +30,28 @@ class GaoDeApiUtils {
params.put("location", location) params.put("location", location)
params.put("extensions","all") params.put("extensions","all")
String content String content
def stop = true
JSONObject jsonObj = null
def errorCount = 1
while (stop){
try { try {
content = new HttpRequest().get("http://restapi.amap.com/v3/geocode/regeo", params, "utf-8") content = new HttpRequest().get("http://restapi.amap.com/v3/geocode/regeo", params, "utf-8")
} catch (Exception e) { } catch (Exception e) {
content = new HttpRequest().get("http://restapi.amap.com/v3/geocode/regeo", params, "utf-8") content = new HttpRequest().get("http://restapi.amap.com/v3/geocode/regeo", params, "utf-8")
} }
JSONObject jsonObj = JSONObject.fromObject(content) jsonObj = JSONObject.fromObject(content)
if(jsonObj.status!="1"){ if(jsonObj.status!="1"){
println jsonObj println jsonObj
errorCount ++
Thread.sleep(3000)
if(errorCount>3){
stop = false
} }
}else{
stop = false
}
}
return jsonObj return jsonObj
} }