From 1c23d47c352ef57bbd4a59e00d4d5b4585853f1e Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期四, 15 十月 2020 09:53:25 +0800 Subject: [PATCH] 拼多多搜索bug --- fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableAspect.java | 34 +++++++++++----------------------- 1 files changed, 11 insertions(+), 23 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableAspect.java b/fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableAspect.java index 5e711b6..eb0f67f 100644 --- a/fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableAspect.java +++ b/fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableAspect.java @@ -1,6 +1,5 @@ package com.yeshi.fanli.aspect; -import java.io.IOException; import java.io.PrintWriter; import java.lang.reflect.Method; import java.util.HashMap; @@ -8,6 +7,7 @@ import javax.annotation.Resource; +import com.yeshi.fanli.util.RedisManager; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.Signature; import org.aspectj.lang.annotation.Around; @@ -37,7 +37,7 @@ @Order(4) public class RequestSerializableAspect { @Resource - private JedisPool jedisPool; + private RedisManager redisManager; private ExpressionParser parser = new SpelExpressionParser(); @@ -63,7 +63,7 @@ } @Around("execution(public * com.yeshi.fanli.controller.client.*.*.*(..))") - public Object requestSerializable(ProceedingJoinPoint joinPoint) throws IOException { + public Object requestSerializable(ProceedingJoinPoint joinPoint) throws Throwable { Signature signature = joinPoint.getSignature(); MethodSignature methodSignature = (MethodSignature) signature; Method targetMethod = methodSignature.getMethod(); @@ -96,21 +96,17 @@ String cacheAlias = cacheKey; cacheKey = "rs-" + StringUtil.Md5(cacheKey); // jiedis鍘熷瓙鎬у仛鎷︽埅 - Jedis jedis = jedisPool.getResource(); - long threadId= Thread.currentThread().getId(); - LogHelper.test("杩涘叆鎷︽埅:"+cacheKey+"-"+threadId); + Jedis jedis = redisManager.getJedis(); + long threadId = Thread.currentThread().getId(); try { Constant.waitingThreadSet.add(threadId); String result = null; long startTime = System.currentTimeMillis(); // 绛夊緟鍝嶅簲 while (StringUtil.isNullOrEmpty(result)) { - + result = jedis.set(cacheKey, "1", new SetParams().nx().ex(30)); - LogHelper.error("瑙﹀彂骞跺彂閿�:" + cacheAlias); - LogHelper.error("redis閿�:" + cacheKey); if (StringUtil.isNullOrEmpty(result)) { - LogHelper.test("绛夊緟:"+threadId); try { Thread.sleep(50); } catch (InterruptedException e) { @@ -122,7 +118,6 @@ return null; } } else { - LogHelper.test("鑾峰彇鍒伴攣:"+threadId); break; } } @@ -130,14 +125,9 @@ if (!StringUtil.isNullOrEmpty(result)) { try { return joinPoint.proceed(); - } catch (Throwable e) { - e.printStackTrace(); - LogHelper.errorDetailInfo(e); } finally { - LogHelper.test("鏂规硶鎵ц瀹屾瘯:"+threadId); jedis.del(cacheKey); Constant.waitingThreadSet.remove(Thread.currentThread().getId()); - LogHelper.test("閲婃斁閿�:"+threadId); } } } finally { @@ -145,12 +135,7 @@ } } } catch (Exception e) {// 鍘熷瓙鎬т繚鎶ゅ嚭閿� - try { - return joinPoint.proceed(); - } catch (Throwable e1) { - e.printStackTrace(); - LogHelper.errorDetailInfo(e1); - } + return joinPoint.proceed(); } } @@ -164,7 +149,10 @@ return joinPoint.proceed(); } catch (Throwable e) { e.printStackTrace(); - LogHelper.errorDetailInfo(e); + if (!Constant.IS_TEST) + LogHelper.errorDetailInfo(e); + else + throw e; } finally { } return null; -- Gitblit v1.8.0