|
@@ -13,6 +13,8 @@ import com.tld.util.RedisUtil;
|
|
|
import com.tld.util.SnowflakeUtil;
|
|
|
import org.apache.ibatis.jdbc.Null;
|
|
|
import org.apache.poi.ss.formula.functions.T;
|
|
|
+import org.redisson.api.RLock;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -33,6 +35,9 @@ public class DictionaryServiceImpl implements DictionaryService {
|
|
|
private DictionaryMapper dictionaryMapper;
|
|
|
@Autowired
|
|
|
private RedisUtil redisUtil;
|
|
|
+ //redis锁
|
|
|
+ @Autowired
|
|
|
+ private RedissonClient redissonClient;
|
|
|
|
|
|
//雪花算法
|
|
|
private SnowflakeUtil snowflakeUtil = new SnowflakeUtil(1, 1, 1);
|
|
@@ -41,6 +46,9 @@ public class DictionaryServiceImpl implements DictionaryService {
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Map<String, Object> addDictionary(List<Dictionary> dictionarys) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
+// //redis并发锁
|
|
|
+// RLock lock = redissonClient.getLock(null);
|
|
|
+// lock.lock();
|
|
|
boolean flg = false;
|
|
|
try {
|
|
|
for (Dictionary dictionary : dictionarys) {
|
|
@@ -90,6 +98,13 @@ public class DictionaryServiceImpl implements DictionaryService {
|
|
|
map.put("status", "0009");
|
|
|
map.put("msg", "服务器请求异常,请稍后再试");
|
|
|
}
|
|
|
+// finally {
|
|
|
+// //判断要解锁的key是否已被锁定;判断要解锁的key是否被当前线程持有
|
|
|
+// if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
|
|
+// //释放锁
|
|
|
+// lock.unlock();
|
|
|
+// }
|
|
|
+// }
|
|
|
return map;
|
|
|
}
|
|
|
|