|
1 |
| -// Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved. |
| 1 | +// Copyright (c) 2007-2022 VMware, Inc. or its affiliates. All rights reserved. |
2 | 2 | //
|
3 | 3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
|
4 | 4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
|
|
22 | 22 | import java.util.concurrent.ThreadFactory;
|
23 | 23 |
|
24 | 24 | import com.rabbitmq.client.Channel;
|
| 25 | +import org.slf4j.Logger; |
| 26 | +import org.slf4j.LoggerFactory; |
25 | 27 |
|
26 | 28 | final public class ConsumerWorkService {
|
| 29 | + private static final Logger LOGGER = LoggerFactory.getLogger(ConsumerWorkService.class); |
27 | 30 | private static final int MAX_RUNNABLE_BLOCK_SIZE = 16;
|
28 |
| - private static final int DEFAULT_NUM_THREADS = Runtime.getRuntime().availableProcessors() * 2; |
| 31 | + private static final int DEFAULT_NUM_THREADS = Math.max(1, Utils.availableProcessors()); |
29 | 32 | private final ExecutorService executor;
|
30 | 33 | private final boolean privateExecutor;
|
31 | 34 | private final WorkPool<Channel, Runnable> workPool;
|
32 | 35 | private final int shutdownTimeout;
|
33 | 36 |
|
34 | 37 | public ConsumerWorkService(ExecutorService executor, ThreadFactory threadFactory, int queueingTimeout, int shutdownTimeout) {
|
35 | 38 | this.privateExecutor = (executor == null);
|
36 |
| - this.executor = (executor == null) ? Executors.newFixedThreadPool(DEFAULT_NUM_THREADS, threadFactory) |
37 |
| - : executor; |
| 39 | + if (executor == null) { |
| 40 | + LOGGER.debug("Creating executor service with {} thread(s) for consumer work service", DEFAULT_NUM_THREADS); |
| 41 | + this.executor = Executors.newFixedThreadPool(DEFAULT_NUM_THREADS, threadFactory); |
| 42 | + } else { |
| 43 | + this.executor = executor; |
| 44 | + } |
38 | 45 | this.workPool = new WorkPool<>(queueingTimeout);
|
39 | 46 | this.shutdownTimeout = shutdownTimeout;
|
40 | 47 | }
|
|
0 commit comments