Add one new constructor with threadFactory only (#9773)

Motivation:
In most cases, we want to use MultithreadEventLoopGroup such as NioEventLoopGroup without setting thread numbers but thread name only. So we need to use followed code:
NioEventLoopGroup boss = new NioEventLoopGroup(0, new DefaultThreadFactory("boss"));
It looks a bit confuse or strange for the number 0 due to we only want to set thread name. So it will be better to add new constructor for this case.

Modifications:
add new constructor into all event loop groups, for example: public NioEventLoopGroup(ThreadFactory threadFactory)

Result:
User can only set thread factory without setting the thread number to 0:
NioEventLoopGroup boss = new NioEventLoopGroup(new DefaultThreadFactory("boss"));
This commit is contained in:
stroller 2019-11-18 16:42:44 +08:00 committed by Norman Maurer
parent 2f3622ee63
commit aa2a9931e8
5 changed files with 42 additions and 0 deletions

View File

@ -52,6 +52,14 @@ public final class EpollEventLoopGroup extends MultithreadEventLoopGroup {
this(nThreads, (ThreadFactory) null);
}
/**
* Create a new instance using the default number of threads and the given {@link ThreadFactory}.
*/
@SuppressWarnings("deprecation")
public EpollEventLoopGroup(ThreadFactory threadFactory) {
this(0, threadFactory, 0);
}
/**
* Create a new instance using the specified number of threads and the default {@link ThreadFactory}.
*/

View File

@ -49,6 +49,14 @@ public final class KQueueEventLoopGroup extends MultithreadEventLoopGroup {
this(nThreads, (ThreadFactory) null);
}
/**
* Create a new instance using the default number of threads and the given {@link ThreadFactory}.
*/
@SuppressWarnings("deprecation")
public KQueueEventLoopGroup(ThreadFactory threadFactory) {
this(0, threadFactory, 0);
}
/**
* Create a new instance using the specified number of threads and the default {@link ThreadFactory}.
*/

View File

@ -39,6 +39,15 @@ public class DefaultEventLoopGroup extends MultithreadEventLoopGroup {
this(nThreads, (ThreadFactory) null);
}
/**
* Create a new instance with the default number of threads and the given {@link ThreadFactory}.
*
* @param threadFactory the {@link ThreadFactory} or {@code null} to use the default
*/
public DefaultEventLoopGroup(ThreadFactory threadFactory) {
this(0, threadFactory);
}
/**
* Create a new instance
*

View File

@ -39,6 +39,15 @@ public class LocalEventLoopGroup extends DefaultEventLoopGroup {
super(nThreads);
}
/**
* Create a new instance with the default number of threads and the given {@link ThreadFactory}.
*
* @param threadFactory the {@link ThreadFactory} or {@code null} to use the default
*/
public LocalEventLoopGroup(ThreadFactory threadFactory) {
super(0, threadFactory);
}
/**
* Create a new instance
*

View File

@ -52,6 +52,14 @@ public class NioEventLoopGroup extends MultithreadEventLoopGroup {
this(nThreads, (Executor) null);
}
/**
* Create a new instance using the default number of threads, the given {@link ThreadFactory} and the
* {@link SelectorProvider} which is returned by {@link SelectorProvider#provider()}.
*/
public NioEventLoopGroup(ThreadFactory threadFactory) {
this(0, threadFactory, SelectorProvider.provider());
}
/**
* 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()}.