src/main/java/com/zy/core/cache/SlaveConnection.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/core/channel/TestController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/core/thread/CrnThread.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/zy/core/cache/SlaveConnection.java
@@ -2,19 +2,19 @@ import com.zy.core.ThreadHandler; import com.zy.core.enums.SlaveType; import io.swagger.models.auth.In; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; /** * 线程缓存容器 * Created by vincent on 2020/8/4 */ public class SlaveConnection { private static final String _LINK = "_"; private static Map<String, ThreadHandler> conContain = new ConcurrentHashMap<>(); private static final Map<String, ThreadHandler> conContain = new ConcurrentHashMap<>(); public static void put(SlaveType type, Integer id, ThreadHandler threadHandler) { String key = toKey(type, id); @@ -22,8 +22,8 @@ conContain.put(key, threadHandler); } public static ThreadHandler get(SlaveType type, Integer key) { return conContain.get(toKey(type, key)); public static ThreadHandler get(SlaveType type, Integer id) { return conContain.get(toKey(type, id)); } public static void remove(SlaveType type, Integer id) { src/main/java/com/zy/core/channel/TestController.java
@@ -1,6 +1,7 @@ package com.zy.core.channel; import com.zy.core.cache.MessageQueue; import com.zy.core.enums.SlaveType; import com.zy.core.model.Task; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -15,7 +16,7 @@ public String test(){ Task task = new Task(); task.setId(1); MessageQueue.CRN_QUE.offer(task); MessageQueue.offer(SlaveType.Crn, 1, task); return "ok"; } src/main/java/com/zy/core/thread/CrnThread.java
@@ -3,6 +3,7 @@ import com.zy.core.Slave; import com.zy.core.ThreadHandler; import com.zy.core.cache.MessageQueue; import com.zy.core.enums.SlaveType; import com.zy.core.model.Task; import lombok.Data; import lombok.extern.slf4j.Slf4j; @@ -15,7 +16,6 @@ public class CrnThread implements Runnable, ThreadHandler { private Slave slave; private int distance; public CrnThread(Slave slave) { this.slave = slave; @@ -26,17 +26,12 @@ public void run() { while (true) { try { System.out.println("线程"+slave.getId()+"正在运行"); Task task = MessageQueue.CRN_QUE.poll(); Task task = MessageQueue.poll(SlaveType.Crn, slave.getId()); if (task == null) { System.out.println("无任务"); } else { System.out.println("任务"+task.getId()); } Thread.sleep(3000); } catch (Exception e) { e.printStackTrace();