问题描述
tomcat为什么有自己的类加载器.用户定义类加载器的优点是什么
why tomcat has its own classloader. what is the advantage of having user defined classloader
推荐答案
它将隔离部署到容器中的各种Web应用程序隔离开来.也就是说,(取消)部署另一个Web应用程序不会影响Web应用程序的行为.
It isolates the various webapplications deployed into the container; that is, the behaviour of a webapplication will not be affected by (un)deploying another webapplication.
每个webapp只能看到其自己的类,而不能看到其他应用程序提供的类.这允许不同的Web应用程序使用同一类的不同版本.如果没有这种隔离,部署多个Web应用程序将是一场噩梦.
Each webapp only sees its own classes, not those provided by the other applications. This allows different webapps to use different versions of the same class. Deploying several webapplications would be a nightmare without that isolation.
类似地,OSGI捆绑软件具有自己的类加载器,因此不同的捆绑软件可以使用同一插件的不同版本.再次,这种隔离使添加插件(及其依赖的库)影响系统中其他插件的可能性降低.
Similarly, OSGI bundles get their own class loaders so different bundles can use different versions of the same plugin. Again, this isolation makes it less likely that adding a plugin (with its depedent libraries) will affect the other plugins in the system.
这篇关于为什么我们需要Java中的用户定义的类加载器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!