Showing
1 changed file
with
4 additions
and
8 deletions
@@ -21,8 +21,6 @@ import org.springframework.stereotype.Service; | @@ -21,8 +21,6 @@ import org.springframework.stereotype.Service; | ||
21 | 21 | ||
22 | import javax.annotation.PostConstruct; | 22 | import javax.annotation.PostConstruct; |
23 | import java.util.*; | 23 | import java.util.*; |
24 | -import java.util.concurrent.ExecutorService; | ||
25 | -import java.util.concurrent.Executors; | ||
26 | import java.util.concurrent.TimeUnit; | 24 | import java.util.concurrent.TimeUnit; |
27 | import java.util.stream.Collectors; | 25 | import java.util.stream.Collectors; |
28 | import static com.yoho.tools.common.utils.RandomUtil.getRandom; | 26 | import static com.yoho.tools.common.utils.RandomUtil.getRandom; |
@@ -68,20 +66,18 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ | @@ -68,20 +66,18 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ | ||
68 | 66 | ||
69 | private static final int recPraise = 2; | 67 | private static final int recPraise = 2; |
70 | 68 | ||
71 | - private static ExecutorService executorService = Executors.newSingleThreadExecutor(); | ||
72 | - | ||
73 | private static final String MESSAGE_KEY = "yh:pfcms:grass:auto_praise:list"; | 69 | private static final String MESSAGE_KEY = "yh:pfcms:grass:auto_praise:list"; |
74 | private static final String MESSAGE_SENDING_FLAG = "yh:pfcms:grass:auto_praise:sending"; | 70 | private static final String MESSAGE_SENDING_FLAG = "yh:pfcms:grass:auto_praise:sending"; |
75 | 71 | ||
76 | @PostConstruct | 72 | @PostConstruct |
77 | public void startSendMessageTask(){ | 73 | public void startSendMessageTask(){ |
78 | - executorService.execute(() -> { | 74 | + new Thread(() -> { |
79 | while(true){ | 75 | while(true){ |
80 | List<GrassInBoxAddReq> messageList = platformRedis.range(MESSAGE_KEY, "all", | 76 | List<GrassInBoxAddReq> messageList = platformRedis.range(MESSAGE_KEY, "all", |
81 | GrassInBoxAddReq.class, 0, -1); | 77 | GrassInBoxAddReq.class, 0, -1); |
82 | - logger.info("startSendMessageTask Begin messageList size is {}",messageList.size()); | 78 | + logger.info("startSendMessageTask Begin messageList size is {}",Objects.isNull(messageList) ? 0 : messageList.size()); |
83 | 79 | ||
84 | - if(!messageList.isEmpty()) { | 80 | + if(CollectionUtils.isNotEmpty(messageList)) { |
85 | //在当前线程开始发站内信之前,确保没有别的地方也在跑 | 81 | //在当前线程开始发站内信之前,确保没有别的地方也在跑 |
86 | //在redis 放一个正在处理的标记位, 正常数据量 2w 30s之内可以处理完, 标记位置有效时间10分钟 | 82 | //在redis 放一个正在处理的标记位, 正常数据量 2w 30s之内可以处理完, 标记位置有效时间10分钟 |
87 | Integer sendTime = platformRedis.getValue(MESSAGE_SENDING_FLAG); | 83 | Integer sendTime = platformRedis.getValue(MESSAGE_SENDING_FLAG); |
@@ -123,7 +119,7 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ | @@ -123,7 +119,7 @@ public class GrassUserVirtualImpl implements IGrassVirtualService{ | ||
123 | e.printStackTrace(); | 119 | e.printStackTrace(); |
124 | } | 120 | } |
125 | } | 121 | } |
126 | - }); | 122 | + }).start(); |
127 | } | 123 | } |
128 | 124 | ||
129 | /** | 125 | /** |
-
Please register or login to post a comment