From 411d06c94befe69a773cf2241010a62b79e0e9e3 Mon Sep 17 00:00:00 2001 From: luzhaofeng <574317128@qq.com> Date: Wed, 6 Nov 2019 17:26:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=BA=E5=99=A8=E4=BA=BA=E6=A8=A1=E5=9D=97-?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=AD=BB=E5=BE=AA=E7=8E=AF=E3=80=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=A4=9A=E4=BD=99=E7=9A=84=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../databot/schedule/KMarketScheduling.java | 46 +++++-------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/blockchain-server/blockchain-server-databot/src/main/java/com/blockchain/server/databot/schedule/KMarketScheduling.java b/blockchain-server/blockchain-server-databot/src/main/java/com/blockchain/server/databot/schedule/KMarketScheduling.java index f9b729c..5415067 100644 --- a/blockchain-server/blockchain-server-databot/src/main/java/com/blockchain/server/databot/schedule/KMarketScheduling.java +++ b/blockchain-server/blockchain-server-databot/src/main/java/com/blockchain/server/databot/schedule/KMarketScheduling.java @@ -43,7 +43,7 @@ public class KMarketScheduling { private static final Logger LOG = LoggerFactory.getLogger(KMarketScheduling.class); private static final int DEPTH_TOTAL_AMOUNT = 150; //盘口数据总量 - private static ExecutorService cachedThreadPool = Executors.newFixedThreadPool(100); //异步线程池 + private static ExecutorService cachedThreadPool = Executors.newFixedThreadPool(4); //异步线程池 /*** * 每一秒创建一次K线数据和深度数据 @@ -332,15 +332,14 @@ public class KMarketScheduling { } //格式化数据 float unitPrice = formatValue(depthPrice); + //新创盘口数量 + float newAmount = avgAmount * random.nextInt(100) / 50; + //减去发行总数量 + totalAmount -= newAmount; //判断是否存在相同单价 if (newPrices.containsKey(unitPrice)) { continue; } else { - //新创盘口数量 - float newAmount = avgAmount * random.nextInt(100) / 50; - //减去发行总数量 - totalAmount -= newAmount; - //构建盘口数据对象 MarketDTO marketDTO = new MarketDTO(new BigDecimal(unitPrice + ""), new BigDecimal(newAmount + ""), new BigDecimal(newAmount + ""), unitName, coinName, tradingType); @@ -377,20 +376,10 @@ public class KMarketScheduling { tuples.add(tuple); } - boolean lockFlag = false; - //获取锁并更新缓存 - while (!lockFlag) { - lockFlag = orderCache.tryFairLock(coinName, unitName, tradingType); - //获取锁成功 - if (lockFlag) { - //删除集合中所有数据 - orderCache.removeZSetByRange(coinName, unitName, tradingType, 0, -1); - //将新数据设置进缓存中 - orderCache.setZSetValue(coinName, unitName, tradingType, tuples); - //释放锁 - orderCache.unFairLock(coinName, unitName, tradingType); - } - } + //删除集合中所有数据 + orderCache.removeZSetByRange(coinName, unitName, tradingType, 0, -1); + //将新数据设置进缓存中 + orderCache.setZSetValue(coinName, unitName, tradingType, tuples); } /*** @@ -524,21 +513,8 @@ public class KMarketScheduling { * @param totalAmount */ private void setUpOneDayKTotalAmount(String currencyPair, BigDecimal totalAmount) { - //锁key - String lockKey = currencyConfigCache.getCurrencyKDayAmountLockKey(currencyPair); - //锁标识 - boolean lockFlag = false; - //循环获取锁 - while (!lockFlag) { - lockFlag = currencyConfigCache.tryFairLock(lockKey); - //获取成功 - if (lockFlag) { - //创建每天每天深度数量,设置进缓存中 - createOneDayKTotalAmount(currencyPair, totalAmount); - //释放锁 - currencyConfigCache.unFairLock(lockKey); - } - } + //创建每天每天深度数量,设置进缓存中 + createOneDayKTotalAmount(currencyPair, totalAmount); } /***