Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8806501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:08:29+00:00 2026-06-14T02:08:29+00:00

The following code is from java.sql.DriverManager : public static Connection getConnection(String url,String user, String

  • 0

The following code is from java.sql.DriverManager:

public static Connection getConnection(String url,String user, String password)    {
    // Gets the classloader of the code that called this method, may 
    // be null.
    ClassLoader callerCL = DriverManager.getCallerClassLoader();
    return (getConnection(url, info, callerCL));
 }

My first question is why the result value of DriverManager.getCallerClassLoader(); may be null? I think the caller Class should be user’s own Class, and it is usually AppClassLoader.

The subsequence of above code getConnection(url, info, callerCL), and the method body contains following code snippet.

if(callerCL == null) {
    callerCL = Thread.currentThread().getContextClassLoader();
}    

What’s Thread.currentThread().getContextClassLoader() for? I have gone through the document and can’t understand it.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:08:31+00:00Added an answer on June 14, 2026 at 2:08 am

    To answer your first question,

    why the result value of DriverManager.getCallerClassLoader(); may be null?

    It because, if you see the way its defined in class DriverManager

    /* Returns the caller's class loader, or null if none */
        private static native ClassLoader getCallerClassLoader();
    

    Its a native method and null value can returned.

    To answer your second question:

    What’s Thread.currentThread().getContextClassLoader() for?

    Every thread has a classloader associated with it. If the thread is a main thread then the class loader associated with it a System Class Loader.

    Many a times you create an object by one class loader and this object can be potentially used by a thread started by some other class loader. So getContextClassLoader() lets you access a class loader which not the one which loaded the object and can access the resources available to the Thread’s class loader.

    Here is another thread on the same forum elaborating more on the same topic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the following code: `package com.tom.jam; //import java.sql.Connection; //import java.sql.DriverManager; import java.sql.*; import
Lets say i have the following bit of code import java.sql.Connection; import java.sql.DriverManager; import
I run the following code from command line: public class MemoryTest { public static
Hy i have the following code : import java.sql.*; import java.net.*; public class binsz
Please have a look at the following code DataBaseConnector.java import java.sql.*; import javax.swing.*; public
I am trying to execute windows commands from Java using the following code, Process
i have the following code, taken partly from a Red Black Tree Java implementation.
I'm calling a java program from my python code in the following way: subprocess.check_output([java,
I have the following piece of Java code that reads strings from CSV file.
Following a bug, I've noticed that if I create a java.sql.Timestamp from a java.util.Date,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.