Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why do we restart the server when there is a change in Java class

 
Ramu Kandada
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends I have a small query..
I am using Websphere to build a sample application..when there is a change any Java class we have to restart the server and have to rebuild the application but when there is a change in any JSP we don't restart..evan the JSP on load also instantiates a Servlet..why it is like that??
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't have to restart the whole server.
You should only have to restart the application.

There are a lot of things in a servlet app that get set up at initialization (context objects, instance variables, refrences to other objects, etc).

If you were simply to reload one class, in isolation, you might break dependencies or miss some initialization steps. Therefore, it's much safer to reload the entire application.

JSPs on the other hand, when properly coded, shouldn't have anything in them by markup text. So reloading a single JSP, without reloading the entire app, should be safe.

NOTE: with older, model 1 JSPs, this was not always the case.
 
Reidar Gjerstad
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
You shouldn't have to restart the whole server.
You should only have to restart the application.


Hi Ben

I am a newbie here. I have been wondering exactly the same. I could not find a better forum than "Servlets".

I am using Apache Tomcat. When writing servlets I have found that the only way to see the effects of servlet code change+recompilation is to click "Stop Service", then "Start Service" and reload the page.

You mention that I only have to restart the application. Is there a way to do this with Tomcat, other than Stop/Start/reload?

If more than one application is running, is there a way to Stop/Start only one application?

Br
Reidar Gjerstad
 
Ted Smyth
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not familiar with Tomcat or Websphere, but I imagine that stop service/start service/application applies to your particular application, or at the very least there is an option to do so.

There's no way around this unless you use a third party library like Java Rebel, and I believe that Oracle/BEA Weblogic Webserver has a new "FastSwap" feature (similar to Java Rebel) which will let you make changes to classes without having to restart your application or container.

Here are some links if you'd like to read up some more:

http://www.zeroturnaround.com/javarebel/
http://edocs.bea.com/wls/essex/TechPreview/pdf/FastSwap.pdf
[ December 02, 2008: Message edited by: Ted Smyth ]
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can reload/start/stop applications through the tomcat manager. I also think there is a setting in tomcat configuration to have tomcat reload an application when it detects a change in any of the class files. My tomcat version is 5.028

Originally posted by Reidar Gjerstad:

Hi Ben

I am a newbie here. I have been wondering exactly the same. I could not find a better forum than "Servlets".

I am using Apache Tomcat. When writing servlets I have found that the only way to see the effects of servlet code change+recompilation is to click "Stop Service", then "Start Service" and reload the page.

You mention that I only have to restart the application. Is there a way to do this with Tomcat, other than Stop/Start/reload?

If more than one application is running, is there a way to Stop/Start only one application?

Br
Reidar Gjerstad
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See:
http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html

And, as Bosun has mentioned, if you set the reloadable attribute to true in your Context entry, the application will automatically reload itself whenever you recompile any of the classes.
 
Reidar Gjerstad
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
See:
http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html


Thanks a lot! I will definitely try this out. Appears like the method I have searched for a long time.

BR
Reidar Gjerstad
 
Ted Smyth
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
See:
http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html

And, as Bosun has mentioned, if you set the reloadable attribute to true in your Context entry, the application will automatically reload itself whenever you recompile any of the classes.


That's a nifty feature!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic