From 4589c4d9df12a7515f2e10da275dfa9e2f1b9b15 Mon Sep 17 00:00:00 2001 From: kamhung <22250530@qq.com> Date: Fri, 13 Nov 2015 09:19:18 +0800 Subject: [PATCH] --- src/com/wentch/redkale/net/Transport.java | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/com/wentch/redkale/net/Transport.java b/src/com/wentch/redkale/net/Transport.java index 6f63fa7d1..223ac19a3 100644 --- a/src/com/wentch/redkale/net/Transport.java +++ b/src/com/wentch/redkale/net/Transport.java @@ -40,8 +40,6 @@ public final class Transport { protected final ObjectPool bufferPool; - protected final AtomicInteger index = new AtomicInteger(); - protected final ConcurrentHashMap> connPool = new ConcurrentHashMap<>(); public Transport(Transport transport, InetSocketAddress localAddress, Collection transports) { @@ -142,10 +140,8 @@ public final class Transport { try { if (tcp) { AsynchronousSocketChannel channel = null; - if (rand) { //随机取地址 - int p = 0; - for (int i = index.get(); i < remoteAddres.length; i++) { - p = i; + if (rand) { //取地址 + for (int i = 0; i < remoteAddres.length; i++) { addr = remoteAddres[i]; BlockingQueue queue = connPool.get(addr); if (queue != null && !queue.isEmpty()) { @@ -155,19 +151,14 @@ public final class Transport { } } if (channel == null) channel = AsynchronousSocketChannel.open(group); - try { channel.connect(addr).get(2, TimeUnit.SECONDS); break; } catch (Exception iex) { iex.printStackTrace(); - if (i == remoteAddres.length - 1) { - p = 0; - channel = null; - } + if (i == remoteAddres.length - 1) channel = null; } } - index.set(p); } else { channel = AsynchronousSocketChannel.open(group); channel.connect(addr).get(2, TimeUnit.SECONDS);