title: Java WebSocket with background thread
body: <p>I'm new to Java &amp; i need help on the following issue:</p>
  
  <p>I'm start learning how a websocket app works. My code uses javax.websocket to implement websocket server which convert a POJO to websocket listener as below:</p>
  
  <pre><code>@ServerEndpoint("/sample")
  public class SampleSocket {
      private static Set&lt;Session&gt; clients = Collections.synchronizedSet(new HashSet&lt;Session&gt;());
  
      @OnOpen
      public void onOpen(Session session) {
          // handle connection open here
      }
  
      @OnClose
      public void onClose(Session session) {
          // handle connection close here
      }
  
      @OnMessage
      public void onMessage(Session session) {
          // handle incoming message here
      }
  
      @OnError
      public void onError(Session session) {
          // handle error here
      }
  }
  </code></pre>
  
  <p>Above code works.</p>
  
  <p>Now, I want to create a new background thread to do some preparations before the server enter listening mode and/or keep track of some other info. But I have no idea how instantiate this background thread. SampleSocket constructor seems not to work.</p>
  
  <p>Thanks in advance.</p>