tomcat的机制

发布于 2024-08-26 06:48:46 字数 272 浏览 3 评论 0原文

这是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野鹿林 2024-09-02 06:48:46

tomcat 时会加载所有类吗
即使没有也开始
请求?

答案是也许。使用的策略取决于您的 JVM 实现。通常,类仅在需要时才加载。

或者他们加载必要的类时
请求进来了吗?

同样,这取决于 JVM 的类加载器策略。一般来说,类仅在需要时才加载。例如,如果请求 1 不需要类 Foo 但请求 2 需要,则该类将仅在请求 2 期间加载。

那么它的生命周期又是怎样的呢?
加载类?

类的实例遵循正常的垃圾收集规则,因此当不再有任何对它们的引用时,它们将被删除。至于课程本身,我不太确定。我想象它们遵循类似的模式,即如果没有剩余的类实例并且 JVM 需要更多内存,它们就会卸载该类。

Do they load all classes when tomcat
is started even when there is no
request?

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.

Or they load necessary classes when a
request comes in?

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.

And how about the life cycle of the
loaded classes?

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文