File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Background Compilation of Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Background Compilation of Servlets" Watch "Background Compilation of Servlets" New topic
Author

Background Compilation of Servlets

Sumeet H Singh
Greenhorn

Joined: Jan 03, 2009
Posts: 29
Hi,
Had a doubt regarding the re-compilation of a servlet after server start-up. If JSPs can be recompiled after they have been changed (after the deployment and server start-up) and their changes are reflected, why is it so that the same is not possible for servlets considering the fact that JSPs are also converted to servlets later?


Sumeet
SCJP, SCWCD
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9305
    
  17

Hi Sumeet, welcome to javaranch.

I'm afraid but your name is not according to the javaranch naming policy, so please change it...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16141
    
  21

It is possible. However there are restrictions.

First, your webserver has to support dynamic class updating. Secondly, that feature has to be switched on. Tomcat manages updated classes by periodically polling for changes, which is extra overhead. So if you want reduced overhead, you'd disable it. Also, it polls fairly infrequently, so it can take a minute or so for the updated class to be seen.

My current system actually stops and restarts the entire webapp when a class changes, but it's not reliable. I've seen issues with servlets because the init() method wasn't called again after the new version of the class loaded, also.

It's not just servlets that can be replaced on the fly. Any Java class can be updated in a live webapp if the appserver supports it.


Customer surveys are for companies who didn't pay proper attention to begin with.
Sumeet H Singh
Greenhorn

Joined: Jan 03, 2009
Posts: 29
Thanks Tim for the detailed reply...
Can you please also specify how to switch-on the facility for Dynamic Class Loading in Apache Tomcat 6.0 ?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16141
    
  21

I'll have to commend you to the documentation for the Tomcat 6.0 system at http://tomcat.apache.org - It's not something I have memorized.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Background Compilation of Servlets