That is an open bug with no good solution (yet)
There are 2 current workarounds on standalone client use at the moment.
1) use System.exit() on your standalone when you want to shutdown cleanly.
package jetty.jsr356;
import java.net.URI;
import java.util.concurrent.CountDownLatch;
import javax.websocket.ClientEndpoint;
import javax.websocket.CloseReason;
import javax.websocket.ContainerProvider;
import javax.websocket.OnClose;
import javax.websocket.WebSocketContainer;
@ClientEndpoint
public class TestClientA
{
private CountDownLatch closeLatch = new CountDownLatch(1);
@OnClose
public void onClose(CloseReason close)
{
closeLatch.countDown();
}
public void waitForClose() throws InterruptedException
{
closeLatch.await();
}
public static void main(String[] args)
{
try
{
WebSocketContainer ws = ContainerProvider.getWebSocketContainer();
TestClientA socket = new TestClientA();
ws.connectToServer(socket,new URI("ws://wuhu.wuhu"));
socket.waitForClose();
}
catch (Throwable t)
{
t.printStackTrace();
}
finally
{
System.exit(0);
}
}
}
2) or use the Jetty specific lifecycle to shutdown the container.
package jetty.jsr356;
import java.net.URI;
import java.util.concurrent.CountDownLatch;
import javax.websocket.ClientEndpoint;
import javax.websocket.CloseReason;
import javax.websocket.ContainerProvider;
import javax.websocket.OnClose;
import javax.websocket.WebSocketContainer;
import org.eclipse.jetty.util.component.LifeCycle;
@ClientEndpoint
public class TestClientB
{
private CountDownLatch closeLatch = new CountDownLatch(1);
@OnClose
public void onClose(CloseReason close)
{
closeLatch.countDown();
}
public void waitForClose() throws InterruptedException
{
closeLatch.await();
}
public static void main(String[] args)
{
try
{
WebSocketContainer ws = ContainerProvider.getWebSocketContainer();
try
{
TestClientB socket = new TestClientB();
ws.connectToServer(socket,new URI("ws://wuhu.wuhu"));
socket.waitForClose();
}
finally
{
if (ws instanceof LifeCycle)
{
((LifeCycle)ws).stop();
}
}
}
catch (Throwable t)
{
t.printStackTrace();
}
}
}