首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

HIbernate的单例事例

2013-11-20 
HIbernate的单例例子例子一:package org.hibernate.internal.util/** * This exists purely to allow cus

HIbernate的单例例子
例子一:

package org.hibernate.internal.util;/** * This exists purely to allow custom ClassLoaders to be injected and used * prior to ServiceRegistry and ClassLoadingService existence.  This should be * replaced in Hibernate 5. *  * @author Brett Meyer */public class ClassLoaderHelper {public static ClassLoader overridenClassLoader = null;public static ClassLoader getContextClassLoader() {return overridenClassLoader != null ?overridenClassLoader : Thread.currentThread().getContextClassLoader();}}


这里通过thread获取了Context classloader
官方api如下:

Returns the context ClassLoader for this Thread. The context ClassLoader is provided by the creator of the thread for use by code running in this thread when loading classes and resources. If not set, the default is the ClassLoader context of the parent Thread. The context ClassLoader of the primordial thread is typically set to the class loader used to load the application.

If a security manager is present, and the invoker's class loader is not null and is not the same as or an ancestor of the context class loader, then this method invokes the security manager's checkPermission method with a RuntimePermission("getClassLoader") permission to verify that retrieval of the context class loader is permitted.

Returns:
the context ClassLoader for this Thread, or null indicating the system class loader (or, failing that, the bootstrap class loader)
Throws:
SecurityException - if the current thread cannot get the context ClassLoader
Since:
1.2

热点排行