title: WebSocket The remote endpoint was in state [TEXT_PARTIAL_WRITING]
body: <p>I'm using tomcat 8.0.15, spring 4.1.5.</p>
  
  <p>I implemented 3 mandatory functions for using websocket like below.
  It's very simple.</p>
  
  <pre><code>private Map&lt;String, WebSocketSession&gt; map_users = new ConcurrentHashMap&lt;&gt;();
  private Map&lt;String, String&gt; map_id = new ConcurrentHashMap&lt;&gt;();
  
  public void afterConnectionEstablished(WebSocketSession wss) throws Exception {
      map_users.put(wss.getId(), wss);
  }
  
  public void afterConnectionClosed(WebSocketSession wss, CloseStatus cs) throws Exception {
      map_users.remove(wss.getId());
  
      // remove user
      String username = map_id.get(wss.getId());
      if (username != null) {
          map_id.remove(wss.getId());
          map_id.remove(username);
      }
  }
  
  public void handleTextMessage(WebSocketSession wss, TextMessage tm) throws Exception {
      String str = tm.getPayload();
      String username = ...;
  
      // regist user
      if (!map_id.get(wss.getId())) {
          map_id.put(wss.getId(), username);
          map_id.put(username, wss.getId());
      }
  
      for (WebSocketSession w: map_users.values()) {
          w.sendMessage(new TextMessage(wss.getId() + " send to " + w.getId() + ", msg:" + tm.getPayload()));
      }
  }
  </code></pre>
  
  <p>Some client sends a message and other clients get the message by the handleTextMessage.</p>
  
  <p>In my case, without the handleTextMessage function, server program wants to send a text message to clients.
  (for this I saved a WebSocketSession's Id and username into map_id)</p>
  
  <pre><code>String websocketsesssion_id = map_id.get(username);
  WebSocketSession wss = map_users.get(websocketsesssion_id);
  wss.sendMessage(new TextMessage(new java.util.Date()));
  </code></pre>
  
  <p>Above code works very well.
  But when some client's WebSocketSession is in use and try to use simultaneously, it makes error.
  It means
      1. some client send message --> handleTextMessage is called --> the client's WebSocketSession is using
      2. server program wants to send message to that client --> get the client's WebSocketSession from map --> try to send message with the same WebSocketSession</p>
  
  <pre><code>Stacktrace:] with root cause
  java.lang.IllegalStateException: The remote endpoint was in state [TEXT_PARTIAL_WRITING] which is an invalid state for called method
      at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.checkState(WsRemoteEndpointImplBase.java:1092)
      at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.textPartialStart(WsRemoteEndpointImplBase.java:1050)
      at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendPartialString(WsRemoteEndpointImplBase.java:218)
      at org.apache.tomcat.websocket.WsRemoteEndpointBasic.sendText(WsRemoteEndpointBasic.java:49)
      at org.springframework.web.socket.adapter.standard.StandardWebSocketSession.sendTextMessage(StandardWebSocketSession.java:197)
      at org.springframework.web.socket.adapter.AbstractWebSocketSession.sendMessage(AbstractWebSocketSession.java:105)
      at org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession.writeFrameInternal(WebSocketServerSockJsSession.java:222)
      at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.writeFrame(AbstractSockJsSession.java:325)
      at org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession.sendMessageInternal(WebSocketServerSockJsSession.java:212)
      at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.sendMessage(AbstractSockJsSession.java:161)
  </code></pre>
  
  <p>As the result, WebSocketSession is closed and client has to open new WebSocketSession again.</p>
  
  <p>So, my question is:</p>
  
  <p>Can I check whether the WebSocketSession is in use or not?
  (outside the handleTextMessage function)</p>