title: How to get an existing websocket instance
body: <p>I'm working on an application that uses Websockets (Java EE 7) to send messages to all the connected clients asynchronously. The server (Websocket endpoint) should send these messages whenever a new article (an engagement modal in my app) is created.</p>
  
  <p>Everytime a connection is established to the websocket endpoint, I'm adding the corresponding session to a list, which I could be able to access outside.</p>
  
  <p>But the problem I had is, when I'm accessing this created websocket endpoint to which all the clients connected from outside (any other business class), I've get the existing instance (like a singleton).</p>
  
  <p>So, can you please suggest me a way I can get an existing instance of the websocket endpoint, as I can't create it as new MyWebsocketEndPoint() coz it'll be created by the websocket internal mechanism whenever the request from a client is received.</p>
  
  <p>For a ref:</p>
  
  <pre><code>private static WebSocketEndPoint INSTANCE = null;
  
  public static WebSocketEndPoint getInstance() {
  if(INSTANCE == null) {
  // Instead of creating a new instance, I need an existing one
      INSTANCE = new WebSocketEndPoint ();
  }
          return INSTANCE;
  }
  </code></pre>
  
  <p>Thanks in advance.</p>