| | |
| | | import javax.websocket.*; |
| | | import javax.websocket.server.ServerEndpoint; |
| | | import java.io.IOException; |
| | | import java.sql.SQLException; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | |
| | | private volatile Thread thread; |
| | | |
| | | private static final int executeTime = 5000; |
| | | |
| | | private static boolean exit=false; |
| | | |
| | | private static Map<String,Thread> threadMap = new HashMap<>(); |
| | | |
| | |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | threadBefore.interrupt(); |
| | | exit=true; |
| | | } |
| | | thread = new Thread("Thread_RealTime") { |
| | | public void run() { |
| | | while (!thread.isInterrupted()) { |
| | | exit=false; |
| | | while ( !thread.isInterrupted()&&!exit) { |
| | | try { |
| | | if (session.isOpen()) { |
| | | session.getBasicRemote().sendObject(service.serchByCondition(Integer.valueOf(battGroupId))); |
| | | } |
| | | sleep(executeTime); |
| | | } catch (IOException | InterruptedException | EncodeException e) { |
| | | } catch ( IOException | InterruptedException | EncodeException e ) { |
| | | interrupt(); |
| | | } |
| | | } |