diff --git a/src/org/redkale/source/PoolTcpSource.java b/src/org/redkale/source/PoolTcpSource.java index 53e76d4b7..51f49c77a 100644 --- a/src/org/redkale/source/PoolTcpSource.java +++ b/src/org/redkale/source/PoolTcpSource.java @@ -11,7 +11,7 @@ import java.nio.channels.*; import java.sql.*; import java.util.*; import java.util.concurrent.*; -import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.*; import java.util.logging.*; import org.redkale.net.AsyncConnection; import static org.redkale.source.DataSources.*; @@ -39,7 +39,25 @@ public abstract class PoolTcpSource extends PoolSource { this.bufferPool = bufferPool; this.executor = executor; try { - this.group = AsynchronousChannelGroup.withFixedThreadPool(executor.getCorePoolSize(), executor.getThreadFactory()); + final String cname = this.getClass().getSimpleName() + "-" + rwtype; + final Thread.UncaughtExceptionHandler ueh = (t, e) -> { + logger.log(Level.SEVERE, cname + " error", e); + }; + final AtomicInteger counter = new AtomicInteger(); + ThreadFactory tf = (Runnable r) -> { + Thread t = new Thread(r); + t.setDaemon(true); + String s = "" + counter.incrementAndGet(); + if (s.length() == 1) { + s = "00" + s; + } else if (s.length() == 2) { + s = "0" + s; + } + t.setName(cname + "-Thread-" + s); + t.setUncaughtExceptionHandler(ueh); + return t; + }; + this.group = AsynchronousChannelGroup.withFixedThreadPool(executor.getCorePoolSize(), tf); } catch (IOException e) { throw new RuntimeException(e); }