| | |
| | | |
| | | private Session session; |
| | | |
| | | private Thread thread; |
| | | private volatile Thread thread; |
| | | |
| | | private static AlarmDataService alarmDataService; |
| | | |
| | |
| | | //UserInf user = new UserInf(); |
| | | //user.setUId(1001L); |
| | | ServletContext servletContext = httpSession.getServletContext(); |
| | | Thread thread = new Thread() { |
| | | thread = new Thread() { |
| | | @Override |
| | | public void run() { |
| | | try{ |
| | | while (!currentThread().isInterrupted()) { |
| | | Response res = alarmDataService.getWavRead4Socket(user,servletContext,httpSession); |
| | | session.getBasicRemote().sendObject(new Response().set(1, res)); |
| | | sleep(2000); |
| | | } |
| | | } catch (Exception e) { |
| | | this.interrupt(); |
| | | } |
| | | } |
| | | }; |
| | | thread.start(); |
| | | this.thread = thread; |
| | | } |
| | | |
| | | @OnClose |
| | |
| | | if(session.isOpen()){ |
| | | session.close(); |
| | | } |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | | } |
| | | |
| | | @OnError |
| | | public void onError(Throwable error) throws IOException { |
| | | //error.printStackTrace(); |
| | | thread.isInterrupted(); |
| | | if(session.isOpen()){ |
| | | session.close(); |
| | | } |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | | } |
| | | |
| | | } |