• Post Reply Bookmark Topic Watch Topic
  • New Topic

why do we restart an application when we make changes to servlet - java/class file  RSS feed

 
Arul Jose
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why do we restart an application when we make changes to a servlet - java/class file?
[ February 28, 2006: Message edited by: Arul Jose ]
 
Kj Reddy
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because if you do not restart you changes wont reflect in the application.
[ February 28, 2006: Message edited by: KJ Reddy ]
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that it depends upon the Servlet Container / Application Server you are using. You can configure them to reload Servlet without restart.
 
Manish Hatwalne
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's right! In Tomcat you can simply set "reloadable" attribute to true in the "context" and then you can deploy your servlets while Tomcat is running.

- Manish
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's worth noting that updating files in the WEB-INF folder will lead to the complete web app being restarted, not just one single class being reloaded (which is not possible due to the nature of web apps being implemented through various classloaders).
 
dema rogatkin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hopefully sessions get preserved between restarts.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by dema rogatkin:
Hopefully sessions get preserved between restarts.


They will as long as all objects bound to them (directly or indirectly) implement Serializable.
 
ak pillai
author
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most servers can reload a servlet after its class file has been modified provided the servlets are deployed to $server_root/servlets directory. This is achieved with the help of a custom class loader. This feature is handy for development and test phases. This is not recommended for production since it can degrade performance because of timestamp comparison for each request to determine if a class file has changed. So for production it is recommended to move the servlet to server´┐Żs class path ie $server_root/classes.

When a server dispatches a request to a servlet, the server first checks if the servlet's class file has changed on disk. If it has changed, the server abandons the class loader used to load the old version and creates a new instance of the custom class loader to load the new version. Old servlet versions can stay in memory indefinitely (so the effect is the other classes can still hold references to the old servlet instances, causing odd side effects, but the old versions are not used to handle any more requests. Servlet reloading is not performed for classes found in the server's classpath because the core, primordial class loader, loads those classes. These classes are loaded once and retained in memory even when their class files change.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ak pillai, when copying someone else's work, it's customary to attribute the source.

The passage copied here is from Jason Hunter's book "Java Servlet Programming".
[ March 01, 2006: Message edited by: Bear Bibeault ]
 
dema rogatkin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally I found that class update feature works not quite well especially when some resources taken using class loader. After updating classes, resources can't be downloaded anymore. I can tell only for web logic. I didn't try tomcatand other app servers though
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!