From 3d8143c36e30336c8728b67a2bae182e4068a2dd Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 21 Mar 2013 16:28:30 +1100 Subject: [PATCH] Use Bungee thread pool for additional logging --- .../main/java/net/md_5/bungee/BungeeCord.java | 3 ++- .../bungee/scheduler/BungeeThreadPool.java | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 proxy/src/main/java/net/md_5/bungee/scheduler/BungeeThreadPool.java diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index 755e1fcc7..b76ce59c4 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -50,6 +50,7 @@ import net.md_5.bungee.config.YamlConfig; import net.md_5.bungee.netty.PipelineUtils; import net.md_5.bungee.packet.DefinedPacket; import net.md_5.bungee.packet.PacketFAPluginMessage; +import net.md_5.bungee.scheduler.BungeeThreadPool; /** * Main BungeeCord proxy class. @@ -76,7 +77,7 @@ public class BungeeCord extends ProxyServer /** * Thread pools. */ - public final ScheduledThreadPoolExecutor executors = new ScheduledThreadPoolExecutor( Integer.MAX_VALUE, + public final ScheduledThreadPoolExecutor executors = new BungeeThreadPool( Integer.MAX_VALUE, new ThreadFactoryBuilder().setNameFormat( "Bungee Pool Thread #%1$d" ).build() ); public final MultithreadEventLoopGroup eventLoops = new NioEventLoopGroup( 0, new ThreadFactoryBuilder().setNameFormat( "Netty IO Thread #%1$d" ).build() ); /** diff --git a/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeThreadPool.java b/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeThreadPool.java new file mode 100644 index 000000000..dde8ab40d --- /dev/null +++ b/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeThreadPool.java @@ -0,0 +1,25 @@ +package net.md_5.bungee.scheduler; + +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.ThreadFactory; +import java.util.logging.Level; +import net.md_5.bungee.api.ProxyServer; + +public class BungeeThreadPool extends ScheduledThreadPoolExecutor +{ + + public BungeeThreadPool(int corePoolSize, ThreadFactory threadFactory) + { + super( corePoolSize, threadFactory ); + } + + @Override + protected void afterExecute(Runnable r, Throwable t) + { + super.afterExecute( r, t ); + if ( t != null ) + { + ProxyServer.getInstance().getLogger().log( Level.SEVERE, "Task caused exception whilst running", t ); + } + } +}