From acc809b3ae930177f2dfcf0e1dac686277e13bec Mon Sep 17 00:00:00 2001 From: Jian Shen Date: Sat, 2 Jul 2022 15:35:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A4=9A=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../temp/shenjian/poi/GetPoiFromCommunity.groovy | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/GetPoiFromCommunity.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/GetPoiFromCommunity.groovy index c466f3250..1aab2c40b 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/GetPoiFromCommunity.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/GetPoiFromCommunity.groovy @@ -14,6 +14,7 @@ import org.elasticsearch.index.query.QueryBuilder import org.elasticsearch.index.query.QueryBuilders import java.util.concurrent.ConcurrentHashMap +import java.util.concurrent.CountDownLatch import java.util.concurrent.ExecutorService import java.util.concurrent.Executors import java.util.concurrent.atomic.AtomicLong @@ -33,6 +34,7 @@ class GetPoiFromCommunity { AtomicLong atomicLong = new AtomicLong(0) Map map = new ConcurrentHashMap<>() def rets = this.findCommunities() + CountDownLatch countDownLatch = new CountDownLatch(rets.size()) for (def retTemp : rets) { final def ret = retTemp executorService.submit(new Runnable() { @@ -59,6 +61,7 @@ class GetPoiFromCommunity { } synchronized (map) { map.put(id, id) + countDownLatch.countDown() if (map.size() % 100 == 0) { atomicLong.addAndGet(map.size()) List ids = map.values().stream().collect(Collectors.toList()) @@ -70,7 +73,15 @@ class GetPoiFromCommunity { } }) } - executorService.shutdown() + countDownLatch.await() + if (map.size() > 0) { + atomicLong.addAndGet(map.size()) + List ids = map.values().stream().collect(Collectors.toList()) + EsUtils.bulkUpdateFieldByIds("community", "crawl_flag", 0, ids) + map.clear() + println(atomicLong.intValue()) + } + System.exit(1) } static def findCommunities(){