一、前言
关于jena源码包中com.hp.hpl.jena.util.SystemUtils系统工具类,按照类加载加载顺序分别通过当前线程执行上下文类加载器Thread.currentThread().getContextClassLoader(),否则获取应用程序类加载器ClassLoader.getSystemClassLoader(),详情参见源码示例。
二、源码示例
package com.hp.hpl.jena.util;@b@@b@import com.hp.hpl.jena.shared.JenaException;@b@import org.slf4j.Logger;@b@import org.slf4j.LoggerFactory;@b@@b@public class SystemUtils@b@{@b@ private static Logger log = LoggerFactory.getLogger(SystemUtils.class.getName());@b@@b@ public static ClassLoader chooseClassLoader()@b@ {@b@ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();@b@@b@ if (classLoader != null)@b@ log.trace("Using thread classloader");@b@@b@ if (classLoader == null)@b@ {@b@ classLoader = ClassLoader.getSystemClassLoader();@b@ if (classLoader != null)@b@ log.trace("Using system classloader");@b@ }@b@@b@ if (classLoader == null)@b@ throw new JenaException("Failed to find a classloader");@b@@b@ return classLoader;@b@ }@b@}