Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Shut down all executor services in SchedulerMain when killing a topol…
Browse files Browse the repository at this point in the history
…ogy (#520)

Shut down all executor services in SchedulerMain when killing a topology.
  • Loading branch information
maosongfu committed May 1, 2016
1 parent 5b2c908 commit e22602a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.sun.net.httpserver.HttpServer;
Expand All @@ -34,12 +36,13 @@ public class SchedulerServer {

private final HttpServer schedulerServer;
private final Config runtime;
private final ExecutorService executorService = Executors.newSingleThreadExecutor();

public SchedulerServer(Config runtime, IScheduler scheduler, int port)
throws IOException {

this.runtime = runtime;
this.schedulerServer = createServer(port);
this.schedulerServer = createServer(port, executorService);

// associate handlers with the URL service end points
this.schedulerServer.createContext(KILL_REQUEST_CONTEXT,
Expand All @@ -55,6 +58,10 @@ public void start() {

public void stop() {
schedulerServer.stop(0);

// Stopping the server will not shut down the Executor
// We have to shut it down explicitly
executorService.shutdownNow();
}

public String getHost() {
Expand All @@ -65,9 +72,9 @@ public int getPort() {
return schedulerServer.getAddress().getPort();
}

protected HttpServer createServer(int port) throws IOException {
protected HttpServer createServer(int port, Executor executor) throws IOException {
HttpServer server = HttpServer.create(new InetSocketAddress(port), SERVER_BACK_LOG);
server.setExecutor(Executors.newSingleThreadExecutor());
server.setExecutor(executor);
return server;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void initialize(Config mConfig, Config mRuntime) {

@Override
public void close() {

monitorService.shutdownNow();
}

/**
Expand Down

0 comments on commit e22602a

Please sign in to comment.