my dog learned polymorphism*
The moose likes Servlets and the fly likes Why do we restart the server when there is a change in Java class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why do we restart the server when there is a change in Java class" Watch "Why do we restart the server when there is a change in Java class" New topic
Author

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

Ramu Kandada
Greenhorn

Joined: Aug 05, 2008
Posts: 4
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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Reidar Gjerstad
Greenhorn

Joined: Dec 02, 2008
Posts: 19
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

Joined: May 28, 2008
Posts: 73
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 ]

Edward Smith
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
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


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Dec 02, 2008
Posts: 19
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

Joined: May 28, 2008
Posts: 73
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!
 
Consider Paul's rocket mass heater.
 
subject: Why do we restart the server when there is a change in Java class
 
Similar Threads
Restarting Websphere v5.0 Test Environment
This Week's GiveAway
refresh of class files in sun application server
servlet changes doesn't take effect after rebuild project
please can you clear my doubt?(immediately)