Java EE class loading standard

本秂侑毒 提交于 2019-11-27 22:56:01
Aravind R. Yarram

I did my own research (going through the specs and few blogs) and below is what I've figured

EAR

The spec DOES NOT define or mandate how the class loaders should work within an EAR. It however defines that 

  1. there SHOULD be per thread context class loader for runtime loading of classes
  2. there MIGHT be a hierarchical class loading mechanism for resolving classes (app server vendors are free to implement whichever way they choose to)
  3. 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)

WAR

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.

Reference

Spec: Servlet 2.3, Section: 9.7.2 Web Application Classloader

Spec: Java EE 5, Section: EE.6.2.4.7 Context Class Loader

App Server specifics

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">, JBoss - java2ParentDelegation=false, Geronimo - <java2-delgation-model>false</java2-delegation-model>

Good information. I was researching the same question and came to similar conclusions. One question still remains is, is it recommended to go with Parent Last option? I would think it will be since your application is more portable; you are not dependent on the Appserver libs. You achieve application isolation. I don't see people recommending one way or the other. Did you come across any such best practice recommendations ?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!