Ion Ionascu
Ion Ionascu

Reputation: 552

Tomcat class-reloading for JSPs

How does class-reloading works in Tomcat when it comes to reloading JSPs (I am talking about the internal architecture)?

I know that each JSP is compiled to a Java class. But how does the classloader (which is unique per web application) reload these generated classes given that a classloader does not allow class unloading and without collecting too much garbage?

Upvotes: 3

Views: 966

Answers (3)

acala
acala

Reputation: 356

A JasperLoader instance is the classloader loads jsp generated servlets.

The jsp compiler "throw away" (set to null) the old JasperLoader instance when it generates a newer servlet class file.

Quote from the comments in JspServletWrapper.setServletLastModifiedTime:

Really need to unload the old class but can't do that. Do the next best thing which is throw away the JspLoader so a new loader will be created which will load the new class.

See also where this method is called after compiling.

Upvotes: 2

Jay
Jay

Reputation: 27464

The standard Java class loader never unloads a class. Tomcat has its own class loaders, which can replace an old instance of a class with a new instance, and then orphans the old instance, making it available to the garbage collector in the usual manner.

Somewhere along the line I read that if a class is not used for some specified period of time, Tomcat will unload it. But I can't find any reference for that at the moment.

Upvotes: 0

Related Questions