开发者

Mechanism of 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 tomc开发者_开发技巧at 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜