-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Core: lazy init workerPool #12427
base: main
Are you sure you want to change the base?
Core: lazy init workerPool #12427
Conversation
Hi Laci, |
the actual use-case was HIVE-28759, where I'm about to supply an executorService to SnapshotProducer to be able to submit some jobs during HS2 shutdown even though the API supports scanManifestsWith, I wasn't able to achive my goal, because the static final variable was initialized in when the class is first loaded and used, see:
...so this is an edge-case, when:
I got an exception like:
even this is just an edge-case, the lazy init might look better in general |
I have seen a similar issue here: #12220 |
So let me recap:
|
thanks, it looks like the very same problem, so by using the default worker pool, we need to accept the default "exiting" behavior, which is fine, as long as users can use their own pools instead, that's what's 99% satisfied by scanManifestsWith interface in my case |
exactly! |
protected ExecutorService workerPool() { | ||
return this.workerPool; | ||
return Optional.ofNullable(workerPool).orElseGet(ThreadPools::getWorkerPool); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have checked the code, and there are some places where the workerPool
is accessed directly.
Is this a fancy way of telling:
if (workerPool == null) {
this.workerPool = ThreadPools.getWorkerPool();
}
return workerPool;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I think it's a cool one-liner, assuming that repeatedly calling ThreadPools::getWorkerPool is not expensive, which is true because it just returns the pool from the 2nd call:
public static ExecutorService getWorkerPool() {
return WORKER_POOL;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, looks like I forgot to replace with workerPool(), let me do quickly
FIXED in e50b767
For code paths where an ExecutorService can be provided, the default call to ThreadPools.getWorkerPool() can be deferred until the point of actual usage.