users@tyrus.java.net

connectToServer leaving background threads when the connection fails

From: Kenneth McCarthy <kmccarthy_at_filetrek.com>
Date: Tue, 5 Nov 2013 16:52:57 -0500

tyrus websockets ClientManager connectToServer 'Handshake response not received'
how do I retry the connection without more and more daemon and Grizzly-kernel and Grizzly-worker threads created. Is there a call to Session or client to kill/cleanup Thread-1 to 4 and Grizzly-kernel and Grizzly-worker threads?

Example JAVA main line which attempts forever to make and maintain a connection with a server which may not be running or is periodically restart.

public void onClose(Session session, CloseReason closeReason) {
    latch.countDown();
}


enter code here
public static void main(String[] args) {
    while (true) {
        latch = new CountDownLatch(1);
        ClientManager client = ClientManager.createClient();
        try {
            client.connectToServer(wsListener.class, new URI("wss://<host>/ws"));
            latch.await();
        }
        catch (DeploymentException e) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ie) {
                break;
            }
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }

        client = null;
            latch = null;
            // HERE... clean up
    }
}