次のコードはからのもの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));
}
私の最初の質問は、の結果値DriverManager.getCallerClassLoader();
がnullになる可能性がある理由です。呼び出し元のクラスはユーザー自身のクラスである必要があり、通常はAppClassLoaderです。
上記のコードのサブシーケンスgetConnection(url, info, callerCL)
、およびメソッド本体には、次のコードスニペットが含まれています。
if(callerCL == null) {
callerCL = Thread.currentThread().getContextClassLoader();
}
何のThread.currentThread().getContextClassLoader()
ために?ドキュメントを確認しましたが、理解できません。
ありがとう。