This is my first attempt on technology blogging and I start with my favorite – the class loader. There is a lot of information out there on J2SE class loaders, their delegation model etc but there is very limited information on the JEE class loader delegation models like PARENT_LAST and PARENT_FRIST that you typically see in the application servers. Are these standardized by spec?
After going through the JEE spec and few articles on internet (It has been a while since I did this research and couldn’t remember the article names), below is the summarized answer.
The spec DOES NOT define or mandate how the class loaders should work within an EAR. It however defines that
- There SHOULD be a per thread context class loader for runtime loading of classes
- There MIGHT be a hierarchical class loading mechanism for resolving classes (app server vendors are free to implement whichever way they choose to)
- The top-level class loader (WAR/EAR) MAY delegate to the low-level class loaders (like Bootstrap, extension etc). This is in compliance with J2SE class loader delegation model (PARENT_FIRST in WAS)
- Servlet specification defines and mandates the support of a PARENT_LAST (i.e. WAR/web-inf/classes and WAR/web-inf/lib take precedence over the libraries that come with the app server) class loading model. But this is just for WAR modules.
- The Servlet spec diverges from the standard J2SE delegation model of PARENT_FIRST in this case.
App Server specific details
Interestingly, though, it appears most major app servers support some mechanism of turning off delegation to isolate the application from the app server if necessary (because of conflicts or otherwise):
- WebSphere – “parent-last”
- GlassFish –
<class-loader delegate="false" />in
- JBoss – java2ParentDelegation=false
- Geronimo – <java2-delgation-model>false</java2-delegation-model>
- WebLogic – ???
- Spec: Servlet 2.3, Section: 9.7.2 Web Application Classloader
- Spec: JEE 5, Section: EE.220.127.116.11 Context Class Loader
- Google for “recursion” or click here. Did you mean: recursion
- Google for “ascii art” or click here. Check their logo.
Google is witty that way 😉