欲引入Redisson框架实现分布式锁

This commit is contained in:
xxy 2020-05-26 00:04:00 +08:00
parent 8f1ed88b07
commit be7cbe2d6f
2 changed files with 4 additions and 0 deletions

View File

@ -50,6 +50,8 @@ public class BookVisitAddListener {
log.debug("收到更新数据库消息:" + bookId);
Thread.sleep(1000 * 2);
//TODO 操作共享资源visitCount集群环境下有线程安全问题引入Redisson框架实现分布式锁
//目前visitCount不重要数据可丢失暂不实现分布式锁
Integer visitCount = (Integer) cacheService.getObject(CacheKey.BOOK_ADD_VISIT_COUNT+bookId);
if(visitCount == null){
visitCount = 0 ;

View File

@ -48,6 +48,8 @@ public class BookToEsSchedule {
*/
@Scheduled(fixedRate = 1000 * 60)
public void saveToEs() {
//TODO 引入Redisson框架实现分布式锁
//可以重复更新只是效率可能略有降低所以暂不实现分布式锁
if (cacheService.get(CacheKey.ES_TRANS_LOCK) == null) {
cacheService.set(CacheKey.ES_TRANS_LOCK, "1", 60 * 20);
try {