Add some cleanup to help avoid exceptions on /reload and shutdown/disable

This commit is contained in:
Mike Primm 2011-06-29 01:37:09 -05:00
parent faceab68f1
commit e2b55c3b54
2 changed files with 32 additions and 24 deletions

View File

@ -10,6 +10,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
@ -99,29 +100,36 @@ public class MapManager {
@Override @Override
public void execute(final Runnable r) { public void execute(final Runnable r) {
final Runnable rr = r; final Runnable rr = r;
super.execute(new Runnable() { try {
public void run() { super.execute(new Runnable() {
try { public void run() {
try {
r.run(); r.run();
} catch (Exception x) { } catch (Exception x) {
Log.severe("Exception during render job: " + r); Log.severe("Exception during render job: " + r);
x.printStackTrace(); x.printStackTrace();
}
} }
} });
}); } catch (RejectedExecutionException rxe) { /* Pool shutdown - nominal for reload or unload */
}
} }
@Override @Override
public ScheduledFuture<?> schedule(final Runnable command, long delay, TimeUnit unit) { public ScheduledFuture<?> schedule(final Runnable command, long delay, TimeUnit unit) {
return super.schedule(new Runnable() { try {
public void run() { return super.schedule(new Runnable() {
try { public void run() {
command.run(); try {
} catch (Exception x) { command.run();
Log.severe("Exception during render job: " + command); } catch (Exception x) {
x.printStackTrace(); Log.severe("Exception during render job: " + command);
x.printStackTrace();
}
} }
} }, delay, unit);
}, delay, unit); } catch (RejectedExecutionException rxe) {
return null; /* Pool shut down when we reload or unload */
}
} }
} }
/* This always runs on render pool threads - no bukkit calls from here */ /* This always runs on render pool threads - no bukkit calls from here */
@ -496,10 +504,7 @@ public class MapManager {
} }
public void stopRendering() { public void stopRendering() {
if(renderpool != null) { renderpool.shutdown();
renderpool.shutdown();
renderpool = null;
}
tileQueue.stop(); tileQueue.stop();
} }

View File

@ -45,13 +45,15 @@ public class HttpServer extends Thread {
public void run() { public void run() {
try { try {
ServerSocket s = sock;
while (listeningThread == Thread.currentThread()) { while (listeningThread == Thread.currentThread()) {
try { try {
Socket socket = sock.accept(); Socket socket = s.accept();
HttpServerConnection requestThread = new HttpServerConnection(socket, this); HttpServerConnection requestThread = new HttpServerConnection(socket, this);
requestThread.start(); requestThread.start();
} catch (IOException e) { } catch (IOException e) {
Log.info("map WebServer.run() stops with IOException"); if(listeningThread != null) /* Only report this if we didn't initiate the shutdown */
Log.info("map WebServer.run() stops with IOException");
break; break;
} }
} }
@ -63,13 +65,14 @@ public class HttpServer extends Thread {
public void shutdown() { public void shutdown() {
Log.info("Shutting down webserver..."); Log.info("Shutting down webserver...");
listeningThread = null;
try { try {
if (sock != null) { if (sock != null) {
sock.close(); sock.close();
sock = null;
} }
} catch (IOException e) { } catch (IOException e) {
Log.warning("Exception while closing socket for webserver shutdown", e); Log.warning("Exception while closing socket for webserver shutdown", e);
} }
listeningThread = null;
} }
} }