jiajunwang commented on a change in pull request #1489:
URL: https://github.com/apache/helix/pull/1489#discussion_r513809494
##########
File path:
helix-core/src/main/java/org/apache/helix/messaging/handling/HelixTaskExecutor.java
##########
@@ -192,43 +191,38 @@ public void registerMessageHandlerFactory(String type,
MessageHandlerFactory fac
@Override
public void registerMessageHandlerFactory(String type, MessageHandlerFactory
factory,
int threadpoolSize) {
- if (factory instanceof MultiTypeMessageHandlerFactory) {
+ if (factory instanceof MultiTypeMessageHandlerFactory) {
if (!((MultiTypeMessageHandlerFactory)
factory).getMessageTypes().contains(type)) {
throw new HelixException("Message factory type mismatch. Type: " +
type + ", factory: "
+ ((MultiTypeMessageHandlerFactory) factory).getMessageTypes());
}
} else {
if (!factory.getMessageType().equals(type)) {
throw new HelixException(
- "Message factory type mismatch. Type: " + type + ", factory: " +
factory.getMessageType());
+ "Message factory type mismatch. Type: " + type + ", factory: " +
factory
+ .getMessageType());
}
}
_isShuttingDown = false;
- MsgHandlerFactoryRegistryItem newItem = new
MsgHandlerFactoryRegistryItem(factory, threadpoolSize);
+ MsgHandlerFactoryRegistryItem newItem =
+ new MsgHandlerFactoryRegistryItem(factory, threadpoolSize);
MsgHandlerFactoryRegistryItem prevItem =
_hdlrFtyRegistry.putIfAbsent(type, newItem);
if (prevItem == null) {
- ExecutorService newPool = Executors.newFixedThreadPool(threadpoolSize,
new ThreadFactory() {
- @Override public Thread newThread(Runnable r) {
- return new Thread(r, "HelixTaskExecutor-message_handle_thread_" +
thread_uid.getAndIncrement());
- }
- });
- ExecutorService prevExecutor = _executorMap.putIfAbsent(type, newPool);
- if (prevExecutor != null) {
- LOG.warn("Skip creating a new thread pool for type: " + type + ",
already existing pool: "
- + prevExecutor + ", isShutdown: " + prevExecutor.isShutdown());
- newPool.shutdown();
- newPool = null;
- } else {
+ _executorMap.computeIfAbsent(type, msgType -> {
Review comment:
putIfAbsent is not good since you will need to create the new pool,
check, then close the new pool if there is already an existing one.
This is what I optimized here.
computeIfAbsent won't trigger the compute callback if the key already exists.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]