-
Notifications
You must be signed in to change notification settings - Fork 137
Use a custom executor service if config is set #11
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
Merged
aws-austin-lee
merged 13 commits into
awslabs:master
from
khush-bhatia:custom_thread_pool
Jun 9, 2019
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ac373cf
Use a custom executor service if config is set
khush-bhatia 90dcc79
Fixed null check for threadPool
khush-bhatia ce25299
Removed singleton logic for custom executor and logs
khush-bhatia 90a6d23
Use an interface for thread executor factory
khush-bhatia 88635bf
Use an interface for thread executor factory
khush-bhatia 9f24b1b
Use an interface for thread executor factory
khush-bhatia 7398ba8
Call factory by reflection
khush-bhatia df44fa3
Use ReflectionUtils to load instance
khush-bhatia 0b87634
Merge branch 'master' of github.com:awslabs/aws-glue-data-catalog-cli…
khush-bhatia 54154a8
Added unit tests
khush-bhatia e995202
Updated unit tests
khush-bhatia 1bb77a8
cleaning up
khush-bhatia e8401cc
Removing extra empty lines
khush-bhatia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...og-client-common/src/main/java/com/amazonaws/glue/catalog/util/ThreadExecutorFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package com.amazonaws.glue.catalog.util; | ||
|
|
||
| import com.amazonaws.glue.catalog.metastore.AWSGlueClientFactory; | ||
| import org.apache.hadoop.hive.conf.HiveConf; | ||
| import org.apache.log4j.Logger; | ||
|
|
||
| import java.lang.reflect.Constructor; | ||
| import java.lang.reflect.InvocationTargetException; | ||
| import java.util.concurrent.ExecutorService; | ||
|
|
||
| import java.util.concurrent.ThreadFactory; | ||
|
|
||
| public class ThreadExecutorFactory { | ||
| private static final Logger logger = Logger.getLogger(ThreadExecutorFactory.class); | ||
| public static final String CUSTOM_EXECUTOR_CONF = "hive.metastore.custom.executor.class"; | ||
|
|
||
| public static ExecutorService getCustomThreadPool(HiveConf conf, int numThreads, ThreadFactory threadFactory) { | ||
khush-bhatia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ExecutorService delegateThreadPool = null; | ||
| String customExecutorClass = conf.get(CUSTOM_EXECUTOR_CONF); | ||
| if (customExecutorClass != null && !customExecutorClass.isEmpty()){ | ||
| delegateThreadPool = (ExecutorService) getInstanceByReflection(customExecutorClass, numThreads, threadFactory); | ||
| } | ||
| return delegateThreadPool; | ||
| } | ||
|
|
||
| public static Object getInstanceByReflection(String className, int arg1, ThreadFactory arg2) { | ||
khush-bhatia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| try { | ||
| Class[] argTypes = {Integer.class, java.util.concurrent.ThreadFactory.class}; | ||
| Class classDefinition = Class.forName(className); | ||
| Constructor cons = classDefinition.getConstructor(argTypes); | ||
| Object[] args = {arg1, arg2}; | ||
| return cons.newInstance(args); | ||
| } catch( ClassNotFoundException e ){ | ||
| logger.warn("Exception in initializing custom executor ",e); | ||
| } catch ( NoSuchMethodException e ) { | ||
| logger.warn("Exception in initializing custom executor ", e); | ||
| } catch( InstantiationException e ) { | ||
| logger.warn("Exception in initializing custom executor ", e); | ||
| } catch (IllegalAccessException e ){ | ||
| logger.warn("Exception in initializing custom executor ", e); | ||
| } catch( InvocationTargetException e ){ | ||
| logger.warn("Exception in initializing custom executor ", e); | ||
| } | ||
khush-bhatia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return null; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.