| | |
| | | package com.whyc.webSocket; |
| | | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.service.ProcessSurveyService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.websocket.*; |
| | | import javax.websocket.server.ServerEndpoint; |
| | | import java.io.IOException; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | @Component |
| | |
| | | |
| | | private static final int executeTime = 5000; |
| | | |
| | | private static Map<String,Thread> threadMap = new HashMap<>(); |
| | | private volatile boolean runFlag=true; |
| | | |
| | | private volatile Map<String,Thread> threadMap = new HashMap<>(); |
| | | |
| | | private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); |
| | | |
| | |
| | | public synchronized void onMessage(Session session,String message){ |
| | | thread = new Thread("Thread_processSurvey") { |
| | | public void run() { |
| | | while (true) { |
| | | while (runFlag && !isInterrupted()) { |
| | | Thread thread = currentThread(); |
| | | threadFlagMap.put(thread.getId(), true); |
| | | try { |
| | |
| | | @OnClose |
| | | public void onClose(CloseReason closeReason){ |
| | | System.err.println("closeReason = " + closeReason); |
| | | runFlag = false; |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | | threadMap.remove(session.getId()); |
| | | } |
| | | |
| | | @OnError |
| | |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | | threadMap.remove(session.getId()); |
| | | } |
| | | } |