1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel;
17
18 import io.netty.util.NettyRuntime;
19 import io.netty.util.concurrent.DefaultThreadFactory;
20 import io.netty.util.concurrent.MultithreadEventExecutorGroup;
21 import io.netty.util.internal.SystemPropertyUtil;
22 import io.netty.util.internal.logging.InternalLogger;
23 import io.netty.util.internal.logging.InternalLoggerFactory;
24
25 import java.util.concurrent.ThreadFactory;
26
27
28
29
30
31 public abstract class MultithreadEventLoopGroup extends MultithreadEventExecutorGroup implements EventLoopGroup {
32
33 private static final InternalLogger logger = InternalLoggerFactory.getInstance(MultithreadEventLoopGroup.class);
34
35 private static final int DEFAULT_EVENT_LOOP_THREADS;
36
37 static {
38 DEFAULT_EVENT_LOOP_THREADS = Math.max(1, SystemPropertyUtil.getInt(
39 "io.netty.eventLoopThreads", NettyRuntime.availableProcessors() * 2));
40
41 if (logger.isDebugEnabled()) {
42 logger.debug("-Dio.netty.eventLoopThreads: {}", DEFAULT_EVENT_LOOP_THREADS);
43 }
44 }
45
46
47
48
49 protected MultithreadEventLoopGroup(int nThreads, ThreadFactory threadFactory, Object... args) {
50 super(nThreads == 0? DEFAULT_EVENT_LOOP_THREADS : nThreads, threadFactory, args);
51 }
52
53 @Override
54 protected ThreadFactory newDefaultThreadFactory() {
55 return new DefaultThreadFactory(getClass(), Thread.MAX_PRIORITY);
56 }
57
58 @Override
59 public EventLoop next() {
60 return (EventLoop) super.next();
61 }
62
63 @Override
64 public ChannelFuture register(Channel channel) {
65 return next().register(channel);
66 }
67
68 @Override
69 public ChannelFuture register(Channel channel, ChannelPromise promise) {
70 return next().register(channel, promise);
71 }
72 }