Skip to content

Use a single classloader for java 11 if environment variable is set #461

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
merged 1 commit into from
Sep 29, 2021

Conversation

shreyas-gopalakrishna
Copy link
Member

@shreyas-gopalakrishna shreyas-gopalakrishna commented Sep 22, 2021

If the FUNCTIONS_WORKER_JAVA_SINGLE_CLASSLOADER environment variable is set to true then the following changes are made

  • For java 11 a synchronized singleton classloader is created for usage
  • This fixes the issue - multiple instances of the static variable even though it's in the same class

#412

Comment on lines 43 to 44
classLoaderInstance = new URLClassLoader(urlsForClassLoader);
loadDrivers(classLoaderInstance);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract to function to reuse from above also

synchronized (lock) {
if (classLoaderInstance == null) {
URLClassLoader loader = createURLClassLoaderInstance();
loadDrivers(loader);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like loadDrivers can be moved to createURLClassLoaderInstance

trask
trask previously approved these changes Sep 28, 2021
Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just two minor simplifications

Comment on lines 25 to 26
URLClassLoader classLoader = createURLClassLoaderInstance();
return classLoader;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
URLClassLoader classLoader = createURLClassLoaderInstance();
return classLoader;
return createURLClassLoaderInstance();

Comment on lines 38 to 39
URLClassLoader loader = createURLClassLoaderInstance();
classLoaderInstance = loader;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
URLClassLoader loader = createURLClassLoaderInstance();
classLoaderInstance = loader;
classLoaderInstance = createURLClassLoaderInstance();

trask
trask previously approved these changes Sep 28, 2021
@amamounelsayed amamounelsayed merged commit ff07534 into v3.x Sep 29, 2021
@shreyas-gopalakrishna shreyas-gopalakrishna deleted the shreyas-gopalakrishna/v3-classloader branch November 8, 2022 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants