Uh oh!
There was an error while loading. Please reload this page.
HBASE-24750 : All ExecutorService should use guava ThreadFactoryBuilder - #2196
HBASE-24750 : All ExecutorService should use guava ThreadFactoryBuilder#2196virajjasani wants to merge 2 commits into
Conversation
Apache-HBase
commented
Aug 4, 2020
🎊 +1 overall
This message was automatically generated. |
| Threads.newDaemonThreadFactory("rs(" + name + ")-backup")); | ||
| executor = new ThreadPoolExecutor(1, threads, keepAlive, TimeUnit.SECONDS, | ||
| new LinkedBlockingQueue<>(), | ||
| new ThreadFactoryBuilder().setNameFormat("rs(" + name + ")-backup-pool-%d").build()); |
There was a problem hiding this comment.
Should the thread names follow existing format (dropping '-pool') ?
People may have got used to the current format during debugging.
There was a problem hiding this comment.
The reason why I appended -pool is to actually adhere with current format only. We add -pool in Threads class internally.
Apache-HBase
commented
Aug 4, 2020
Apache-HBase
commented
Aug 4, 2020
🎊 +1 overall
This message was automatically generated. |
| @@ -200,70 +201,7 @@ public static ThreadPoolExecutor getBoundedCachedThreadPool( | |||
| public static ThreadPoolExecutor getBoundedCachedThreadPool(int maxCachedThread, long timeout, | |||
There was a problem hiding this comment.
I wonder if these getBoundedCachedThreadPool methods could be replace to calls to methods directly on java.util.concurrent.Executors. I think we'd need to evaluate on a case-by-case basis how the resulting pools are being used and if they're constructed to correctly match the use-case.
There was a problem hiding this comment.
Agree, at least for now, let me make callers use getBoundedCachedThreadPool with ThreadFactoryBuilder input and only keep that version of getBoundedCachedThreadPool in Threads class.
Uh oh!
There was an error while loading. Please reload this page.
Apache-HBase
commented
Aug 6, 2020
🎊 +1 overall
This message was automatically generated. |
Apache-HBase
commented
Aug 6, 2020
🎊 +1 overall
This message was automatically generated. |
Apache-HBase
commented
Aug 6, 2020
🎊 +1 overall
This message was automatically generated. |
| Thread t = namedFactory.newThread(r); | ||
| if (handler != null) { | ||
| t.setUncaughtExceptionHandler(handler); | ||
| } else { |
There was a problem hiding this comment.
@virajjasani Sorry,I did not explain clear, I wonder if here may cause Inconsistent? In guava's builder class, if we do not assign UncaughtExceptionHandler, the UncaughtExceptionHandler will be null, not LOGGING_EXCEPTION_HANDLER
There was a problem hiding this comment.
compare with hbase-shaded-miscellaneous
private static ThreadFactory doBuild(ThreadFactoryBuilder builder) {
final String nameFormat = builder.nameFormat;
final Boolean daemon = builder.daemon;
final Integer priority = builder.priority;
final UncaughtExceptionHandler uncaughtExceptionHandler = builder.uncaughtExceptionHandler;
final ThreadFactory backingThreadFactory =
(builder.backingThreadFactory != null)
? builder.backingThreadFactory
: Executors.defaultThreadFactory();
final AtomicLong count = (nameFormat != null) ? new AtomicLong(0) : null;
return new ThreadFactory() {
@Override
public Thread newThread(Runnable runnable) {
Thread thread = backingThreadFactory.newThread(runnable);
if (nameFormat != null) {
thread.setName(format(nameFormat, count.getAndIncrement()));
}
if (daemon != null) {
thread.setDaemon(daemon);
}
if (priority != null) {
thread.setPriority(priority);
}
if (uncaughtExceptionHandler != null) {
thread.setUncaughtExceptionHandler(uncaughtExceptionHandler);
}
return thread;
}
};
}
There was a problem hiding this comment.
I see, you are correct. We should not see issue from end result viewpoint if we are just executing some tasks and some exception interrupts executor thread specifically when ThreadGroup takes care of it:
public void uncaughtException(Thread t, Throwable e) {
if (parent != null) {
parent.uncaughtException(t, e);
} else {
Thread.UncaughtExceptionHandler ueh =
Thread.getDefaultUncaughtExceptionHandler();
if (ueh != null) {
ueh.uncaughtException(t, e);
} else if (!(e instanceof ThreadDeath)) {
System.err.print("Exception in thread \""
+ t.getName() + "\" ");
e.printStackTrace(System.err);
}
}
}
However, if we want to maintain the same log present in LOGGING_EXCEPTION_HANDLER as default (which is what used to happen before this patch) behaviour, we should update the corresponding usages with uncaught exception handler as LOGGING_EXCEPTION_HANDLER in all places.
Let me raise a PR for this.
There was a problem hiding this comment.
thank you for explaining about it.
…er (apache#2214) Closesapache#2196 Signed-off-by: Nick Dimiduk <ndimiduk@apache.org> Signed-off-by: Ted Yu <tyu@apache.org> Signed-off-by: niuyulin <nyl353@163.com>
Jira: https://issues.apache.org/jira/browse/HBASE-24750