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.TreeSet;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
@ -99,29 +100,36 @@ public class MapManager {
@Override
public void execute(final Runnable r) {
final Runnable rr = r;
super.execute(new Runnable() {
public void run() {
try {
try {
super.execute(new Runnable() {
public void run() {
try {
r.run();
} catch (Exception x) {
Log.severe("Exception during render job: " + r);
x.printStackTrace();
} catch (Exception x) {
Log.severe("Exception during render job: " + r);
x.printStackTrace();
}
}
}
});
});
} catch (RejectedExecutionException rxe) { /* Pool shutdown - nominal for reload or unload */
}
}
@Override
public ScheduledFuture<?> schedule(final Runnable command, long delay, TimeUnit unit) {
return super.schedule(new Runnable() {
public void run() {
try {
command.run();
} catch (Exception x) {
Log.severe("Exception during render job: " + command);
x.printStackTrace();
try {
return super.schedule(new Runnable() {
public void run() {
try {
command.run();
} catch (Exception x) {
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 */
@ -496,10 +504,7 @@ public class MapManager {
}
public void stopRendering() {
if(renderpool != null) {
renderpool.shutdown();
renderpool = null;
}
renderpool.shutdown();
tileQueue.stop();
}

View File

@ -45,13 +45,15 @@ public class HttpServer extends Thread {
public void run() {
try {
ServerSocket s = sock;
while (listeningThread == Thread.currentThread()) {
try {
Socket socket = sock.accept();
Socket socket = s.accept();
HttpServerConnection requestThread = new HttpServerConnection(socket, this);
requestThread.start();
} 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;
}
}
@ -63,13 +65,14 @@ public class HttpServer extends Thread {
public void shutdown() {
Log.info("Shutting down webserver...");
listeningThread = null;
try {
if (sock != null) {
sock.close();
sock = null;
}
} catch (IOException e) {
Log.warning("Exception while closing socket for webserver shutdown", e);
}
listeningThread = null;
}
}