Skip to content

Commit

Permalink
423646 - WebSocket / JSR / WebSocketContainer (Client) should have it…
Browse files Browse the repository at this point in the history
…s LifeCycle stop on standalone use

+ Set Daemon on Executor and Scheduler threads to allow them to shutdown
  with the JVM
  • Loading branch information
joakime committed Jan 7, 2014
1 parent f0eeb27 commit 44a7d23
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ public class ClientContainer extends ContainerLifeCycle implements WebSocketCont

public ClientContainer()
{
// This constructor is used with Standalone JSR Client usage.
this(null);
client.setDaemon(true);
}

public ClientContainer(Executor executor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class WebSocketClient extends ContainerLifeCycle implements SessionListen
private final WebSocketPolicy policy;
private final SslContextFactory sslContextFactory;
private final WebSocketExtensionFactory extensionRegistry;
private boolean daemon = false;
private EventDriverFactory eventDriverFactory;
private SessionFactory sessionFactory;
private Set<WebSocketSession> openSessions = new CopyOnWriteArraySet<>();
Expand Down Expand Up @@ -227,7 +228,7 @@ protected void doStart() throws Exception

if (scheduler == null)
{
scheduler = new ScheduledExecutorScheduler(name + "-scheduler",false);
scheduler = new ScheduledExecutorScheduler(name + "-scheduler",daemon);
}
addBean(scheduler);

Expand Down Expand Up @@ -290,7 +291,7 @@ public CookieStore getCookieStore()
{
return cookieStore;
}

public EventDriverFactory getEventDriverFactory()
{
return eventDriverFactory;
Expand Down Expand Up @@ -419,6 +420,7 @@ private synchronized void initialiseClient() throws IOException
QueuedThreadPool threadPool = new QueuedThreadPool();
String name = WebSocketClient.class.getSimpleName() + "@" + hashCode();
threadPool.setName(name);
threadPool.setDaemon(daemon);
executor = threadPool;
addBean(executor,true);
}
Expand Down Expand Up @@ -505,6 +507,11 @@ public void setCookieStore(CookieStore cookieStore)
{
this.cookieStore = cookieStore;
}

public void setDaemon(boolean daemon)
{
this.daemon = daemon;
}

public void setEventDriverFactory(EventDriverFactory factory)
{
Expand Down

0 comments on commit 44a7d23

Please sign in to comment.