ThreadクラスのgetContextClassLoader()がnullを返す条件を知りたいです。
Java
1/** 2 * Returns the context {@code ClassLoader} for this thread. The context 3 * {@code ClassLoader} is provided by the creator of the thread for use 4 * by code running in this thread when loading classes and resources. 5 * If not {@linkplain #setContextClassLoader set}, the default is the 6 * {@code ClassLoader} context of the parent thread. The context 7 * {@code ClassLoader} of the 8 * primordial thread is typically set to the class loader used to load the 9 * application. 10 * 11 * 12 * @return the context {@code ClassLoader} for this thread, or {@code null} 13 * indicating the system class loader (or, failing that, the 14 * bootstrap class loader) 15 * 16 * @throws SecurityException 17 * if a security manager is present, and the caller's class loader 18 * is not {@code null} and is not the same as or an ancestor of the 19 * context class loader, and the caller does not have the 20 * {@link RuntimePermission}{@code ("getClassLoader")} 21 * 22 * @since 1.2 23 */ 24 @CallerSensitive 25 public ClassLoader getContextClassLoader() { 26 if (contextClassLoader == null) 27 return null; 28 SecurityManager sm = System.getSecurityManager(); 29 if (sm != null) { 30 ClassLoader.checkClassLoaderPermission(contextClassLoader, 31 Reflection.getCallerClass()); 32 } 33 return contextClassLoader; 34 }
こちらはThreadクラスのgetContextClassLoader()です。
javadocを読んでもいまいちピンと来ません。
どなたか教えてくださいませ。
あなたの回答
tips
プレビュー