Ehcache (2.9.x)-API Developer guide, Class Loading

Source: Internet
Author: User

About Class Loading

Class loading, within the plethora of environments that Ehcache can is running, could be complex. but with the Ehcache, all class loading are done in a standard-of-the-utility class:classloaderutil.

Plugin Class Loading

Ehcache allows plugins for events and distribution. These is loaded and created as follows:

/*** Creates a new class instance. Logs errors along the.  Classes is loaded * using the Ehcache standard ClassLoader. *  * @paramClassName a fully qualified class name *@returnNULL if the instance cannot be loaded*/  Public StaticObject createnewinstance (String className)throwscacheexception {Class clazz;     Object newinstance; Try{clazz= Class.forName (ClassName,true, Getstandardclassloader ()); } Catch(ClassNotFoundException e) {//try fallback        Try{clazz= Class.forName (ClassName,true, Getfallbackclassloader ()); } Catch(ClassNotFoundException ex) {Throw NewCacheexception ("Unable to load class" + ClassName + ". Initial cause was "+e.getmessage (), E); }     }     Try{newinstance=clazz.newinstance (); } Catch(illegalaccessexception e) {Throw NewCacheexception ("Unable to load class" + ClassName + ". Initial cause was "+e.getmessage (), E); } Catch(instantiationexception e) {Throw NewCacheexception ("Unable to load class" + ClassName + ". Initial cause was "+e.getmessage (), E); }     returnnewinstance;} /*** Gets The ClassLoader that all classes in Ehcache, and extensions, * should with for classloading. All classloading the Ehcache should use the This * one.  This was the only thing, seems to work for all of the class * loading situations found in the wild. * @returnThe thread context class loader. */  Public StaticClassLoader Getstandardclassloader () {returnThread.CurrentThread (). Getcontextclassloader ();} /*** Gets A fallback ClassLoader that all classes in Ehcache, and * extensions, should with for classloading.  This is used if the * Context class loader does isn't work. * @returnThe ClassLoaderUtil.class.getClassLoader ();*/  Public StaticClassLoader Getfallbackclassloader () {returnClassloaderutil.class. getClassLoader ();}

If This does isn't work for some reason, a cacheexception are thrown with a detailed error message.

Loading of Ehcache.xml Resources

If the configuration is otherwise unspecified, Ehcache looks for a configuration in the following order:

    • Thread.CurrentThread (). Getcontextclassloader (). GetResource ("/ehcache.xml")
    • ConfigurationFactory.class.getResource ("/ehcache.xml")
    • ConfigurationFactory.class.getResource ("/ehcache-failsafe.xml")

Ehcache uses the first configuration found. Note the use of '/ehcache.xml', which requires that ehcache.xml is placed at the root of the classpath (i.e., not In any package).

Ehcache (2.9.x)-API Developer guide, Class Loading

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.