Allow specifying 0 as the default number of threads when instantiating an EventLoopGroup
- Fixes #1426 - We already allow a user instantiate an EventLoopGroup with the default number of threads via the default constructor, so I think it's OK although it's not always optimal.
This commit is contained in:
parent
1c57e3830c
commit
734ec51ac9
@ -18,8 +18,8 @@ package io.netty.channel;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.buffer.ByteBufHolder;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import io.netty.util.DefaultAttributeMap;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import io.netty.util.internal.PlatformDependent;
|
||||
import io.netty.util.internal.logging.InternalLogger;
|
||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||
@ -715,7 +715,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
||||
if (promise.isCancelled()) {
|
||||
// If cancelled, release all unwritten messages and recycle.
|
||||
for (int i = messageIndex; i < messageCount; i ++) {
|
||||
ByteBufUtil.release(messages.get(i));
|
||||
ReferenceCountUtil.release(messages.get(i));
|
||||
}
|
||||
messages.recycle();
|
||||
if (!outboundBuffer.next()) {
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
package io.netty.channel;
|
||||
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
|
||||
@ -81,7 +81,7 @@ public abstract class AbstractServerChannel extends AbstractChannel implements S
|
||||
reject(promise);
|
||||
int size = msgs.size();
|
||||
for (int i = 0; i < size; i ++) {
|
||||
ByteBufUtil.release(msgs.get(i));
|
||||
ReferenceCountUtil.release(msgs.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
*/
|
||||
package io.netty.channel;
|
||||
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import io.netty.util.internal.logging.InternalLogger;
|
||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||
|
||||
@ -228,7 +228,7 @@ final class ChannelOutboundBuffer {
|
||||
try {
|
||||
for (int i = currentMessageIndex; i < currentMessages.size(); i++) {
|
||||
Object msg = currentMessages.get(i);
|
||||
ByteBufUtil.release(msg);
|
||||
ReferenceCountUtil.release(msg);
|
||||
}
|
||||
} finally {
|
||||
currentMessages.recycle();
|
||||
|
@ -15,8 +15,8 @@
|
||||
*/
|
||||
package io.netty.channel;
|
||||
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import io.netty.channel.Channel.Unsafe;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import io.netty.util.concurrent.EventExecutor;
|
||||
import io.netty.util.concurrent.EventExecutorGroup;
|
||||
import io.netty.util.internal.PlatformDependent;
|
||||
@ -970,7 +970,7 @@ final class DefaultChannelPipeline implements ChannelPipeline {
|
||||
"Discarded inbound message {} that reached at the tail of the pipeline. " +
|
||||
"Please check your pipeline configuration.", m);
|
||||
|
||||
ByteBufUtil.release(m);
|
||||
ReferenceCountUtil.release(m);
|
||||
}
|
||||
|
||||
if (length != 1) {
|
||||
|
@ -31,7 +31,7 @@ public abstract class MultithreadEventLoopGroup extends MultithreadEventExecutor
|
||||
|
||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(MultithreadEventLoopGroup.class);
|
||||
|
||||
public static final int DEFAULT_EVENT_LOOP_THREADS;
|
||||
private static final int DEFAULT_EVENT_LOOP_THREADS;
|
||||
|
||||
static {
|
||||
DEFAULT_EVENT_LOOP_THREADS = Math.max(1, SystemPropertyUtil.getInt(
|
||||
@ -43,7 +43,7 @@ public abstract class MultithreadEventLoopGroup extends MultithreadEventExecutor
|
||||
}
|
||||
|
||||
protected MultithreadEventLoopGroup(int nThreads, ThreadFactory threadFactory, Object... args) {
|
||||
super(nThreads, threadFactory, args);
|
||||
super(nThreads == 0? DEFAULT_EVENT_LOOP_THREADS : nThreads, threadFactory, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,10 +26,10 @@ import java.util.concurrent.ThreadFactory;
|
||||
public class LocalEventLoopGroup extends MultithreadEventLoopGroup {
|
||||
|
||||
/**
|
||||
* Create a new instance which used {@link #DEFAULT_EVENT_LOOP_THREADS} number of Threads
|
||||
* Create a new instance with the default number of threads.
|
||||
*/
|
||||
public LocalEventLoopGroup() {
|
||||
this(DEFAULT_EVENT_LOOP_THREADS);
|
||||
this(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,15 +29,15 @@ import java.util.concurrent.ThreadFactory;
|
||||
public class NioEventLoopGroup extends MultithreadEventLoopGroup {
|
||||
|
||||
/**
|
||||
* Create a new instance using {@link #DEFAULT_EVENT_LOOP_THREADS} number of threads, the default
|
||||
* {@link ThreadFactory} and the {@link SelectorProvider} which is returned by {@link SelectorProvider#provider()}.
|
||||
* Create a new instance using the default number of threads, the default {@link ThreadFactory} and
|
||||
* the {@link SelectorProvider} which is returned by {@link SelectorProvider#provider()}.
|
||||
*/
|
||||
public NioEventLoopGroup() {
|
||||
this(DEFAULT_EVENT_LOOP_THREADS);
|
||||
this(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance using nThreads number of threads, {@link ThreadFactory} and the
|
||||
* Create a new instance using the specified number of threads, {@link ThreadFactory} and the
|
||||
* {@link SelectorProvider} which is returned by {@link SelectorProvider#provider()}.
|
||||
*/
|
||||
public NioEventLoopGroup(int nThreads) {
|
||||
@ -45,7 +45,7 @@ public class NioEventLoopGroup extends MultithreadEventLoopGroup {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance using nThreads number of threads, the given {@link ThreadFactory} and the
|
||||
* Create a new instance using the specified number of threads, the given {@link ThreadFactory} and the
|
||||
* {@link SelectorProvider} which is returned by {@link SelectorProvider#provider()}.
|
||||
*/
|
||||
public NioEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
|
||||
@ -53,7 +53,7 @@ public class NioEventLoopGroup extends MultithreadEventLoopGroup {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance using nThreads number of threads, the given {@link ThreadFactory} and the given
|
||||
* Create a new instance using the specified number of threads, the given {@link ThreadFactory} and the given
|
||||
* {@link SelectorProvider}.
|
||||
*/
|
||||
public NioEventLoopGroup(
|
||||
|
Loading…
Reference in New Issue
Block a user