tomcat的机制
这是 tomcat 加载器结构:
Bootstrap
|
System
|
Common
/ \
Webapp1 Webapp2 ...
我的问题是加载器实际上是如何工作的?
即使没有请求,tomcat 启动时它们也会加载所有类吗?
或者当请求到来时他们加载必要的类?
那么加载的类的生命周期又如何呢?
This is tomcat loader structure:
Bootstrap
|
System
|
Common
/ \
Webapp1 Webapp2 ...
My question is how does the loaders actually work?
Do they load all classes when tomcat is started even when there is no request?
Or they load necessary classes when a request comes in?
And how about the life cycle of the loaded classes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是也许。使用的策略取决于您的 JVM 实现。通常,类仅在需要时才加载。
同样,这取决于 JVM 的类加载器策略。一般来说,类仅在需要时才加载。例如,如果请求 1 不需要类 Foo 但请求 2 需要,则该类将仅在请求 2 期间加载。
类的实例遵循正常的垃圾收集规则,因此当不再有任何对它们的引用时,它们将被删除。至于课程本身,我不太确定。我想象它们遵循类似的模式,即如果没有剩余的类实例并且 JVM 需要更多内存,它们就会卸载该类。
The answer is maybe. The strategy used is down to your JVM implementation. More often than not classes are only loaded when they are required.
Again it depends on your JVM's class loader strategy. Generally speaking though classes are only loaded when they are needed. For example, if request 1 doesn't needed class Foo but request 2 does then the class will only be loaded during request 2.
Instances of the classes follow the normal garbage collection rules so they're deleted when there are no longer any references to them. As for the classes themselves, I'm not entirely sure. I'd imagine they follow a similar pattern, i.e. if there are no instances of the class left and the JVM needs more memory they it unloads the class.