Reputation: 303
Let me ask several questions regarding thread with Netty.
Q1. Which thread is created? According to documentation, following constructor creates multiple threads (2 * the number of avail processors). It means that it creates multiple boss threads or worker threads? My assumption is 1 boss thread and multiple worker thread. Am I correct?
public NioServerSocketChannelFactory(Executor bossExecutor, Executor workerExecutor) Creates a new instance. Calling this constructor is same with calling NioServerSocketChannelFactory(Executor, Executor, int) with 2 * the number of available processors in the machine.
Q2. According to the documentation, it seems to me that I can specify the max number of worker thread with following constructor. Can I implicitly specify exact number of worker thread to create - say 16?
public NioServerSocketChannelFactory(Executor bossExecutor, Executor workerExecutor, int workerCount) Creates a new instance. Parameters: bossExecutor - the Executor which will execute the boss threads workerExecutor - the Executor which will execute the I/O worker threads workerCount - the maximum number of I/O worker threads
Q3. Is there any way to know the number of boss and worker threads that currently run?
Any help is greatly appreciated!
Upvotes: 4
Views: 2905
Reputation: 12351
Q1. Which thread is created? According to documentation, following constructor creates multiple threads (2 * the number of avail processors). It means that it creates multiple boss threads or worker threads? My assumption is 1 boss thread and multiple worker thread. Am I correct?
Yes.
Q2. According to the documentation, it seems to me that I can specify the max number of worker thread with following constructor. Can I implicitly specify exact number of worker thread to create - say 16?
Just specify Executors.newCachedThreadPool()
and specify the max number of threads to use as a constructor parameter.
Q3. Is there any way to know the number of boss and worker threads that currently run?
You can get it via ThreadPoolExecutor.getActiveCount()
assuming you passed Executors.newCachedThreadPool()
. It returns ThreadPoolExecutor
, so you can keep it somewhere and then query it to see how many threads are actually active.
Upvotes: 3