-
Notifications
You must be signed in to change notification settings - Fork 66
Use a single classloader for java 11 #460
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
Conversation
src/main/java/com/microsoft/azure/functions/worker/reflect/EnhancedClassLoaderProvider.java
Show resolved
Hide resolved
|
|
||
| urls.add(url); | ||
| } | ||
| private final Set<URL> urls; |
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.
| private final Set<URL> urls; | |
| private final Set<URL> urls; | |
| private final Object lock = new Object(); |
| */ | ||
| private URLClassLoader getURLClassLoaderInstance(URL[] urlsForClassLoader) { | ||
| if (classLoaderInstance == null) { | ||
| synchronized (URLClassLoader.class) { |
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.
| synchronized (URLClassLoader.class) { | |
| synchronized (lock) { |
| * @param urlsForClassLoader Array of URLs to construct a new URLClassLoader | ||
| * @return single instance of URLClassLoader | ||
| */ | ||
| private URLClassLoader getURLClassLoaderInstance(URL[] urlsForClassLoader) { |
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.
no need to pass args here, calculate below instead
| public ClassLoader createClassLoader() { | ||
| URL[] urlsForClassLoader = new URL[urls.size()]; | ||
| urls.toArray(urlsForClassLoader); | ||
| return createURLClassLoaderInstance(); |
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.
just a style thought, can inline the createURLClassLoaderInstance method here
| classLoaderInstance = new URLClassLoader(urlsForClassLoader); | ||
| loadDrivers(classLoaderInstance); |
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.
good to assign the field at the very end, so that another thread can't come in and return classLoaderInstance prior to it being fully initialized
| classLoaderInstance = new URLClassLoader(urlsForClassLoader); | |
| loadDrivers(classLoaderInstance); | |
| URLClassLoader loader = new URLClassLoader(urlsForClassLoader); | |
| loadDrivers(loader); | |
| classLoaderInstance = loader; |
4f9ba39
61a1d17 to
4f9ba39
Compare
Fixes
Code changes
#412