Servlet Reloading

Servlet reloading is built into Tynamo™. It is possible to turn this feature on or off.

Some definitions are necessary:

Servlet Reloading
In this document, this refers to the mechanism used to load and reload servlets except when they are loaded with the special Loader Servlet.
Loader Servlet
This is a special servlet, optionally included in the build, that can load and reload servlets without specifying them in the servlet configuration file.

Subject Menu


Servlet Configuration

All servlets, including dynamically loaded servlets not loaded by the special Loader Servlet, must be specified in your servlet configuration file. The server cannot find your servlet if it is not declared here.

[Top]


The Servlet Classpath

The reloading mechanism first looks for classes in the default and user classpaths, and then in the paths specified by the servlet.classpath configuration property. Be aware, though, that some platforms may cache classes loaded through these search paths, making them unavailable for reloading. The servlet.classpath property gets around this, so be sure to specify it if your platform is one that caches classes.

It may possible to specify a user classpath by providing a '-classpath' argument. For example (EJC platform) (note that the line may be wrapped, but should be on one line):

java -classpath "/web/bin/tws_core.jar;/web/examples/servlet_examples.jar" com.qindesign.cdc.http.Main /web/bin/webserver.props &

Note that the Loader Servlet does not use this property, and has its own classpath mechanism.

[Top]


Servlet Reloading Internals You Need to Know About

It is possible to turn this feature off with the servlet.reloadingEnabled configuration property. With this value set to false, the servlet container will not search for new classes.

Second, there is a property called servlet.maxTimeBeforeDestroy that controls the maximum amount of time the container spends waiting for uncompleted service calls on a servlet. After this time has elapsed, the servlet is destroyed regardless. While the default value for this property is 20 seconds, the safest is probably an indefinite wait time, indicated by a value of 0 seconds.

To quote from Section 3.3.4 of the servlet 2.2 specification, "End of Service":

"Before the servlet container can call the destroy method, it must allow any threads that are currently running in the service method of the servlet to either complete, or exceed a server defined time limit, before the container can proceed with calling the destroy method."

Third, if a servlet was dynamically loaded and its classfile disappears, then the container will reuse the one it has already loaded. If this is undesirable behaviour, please let us know.

[Top]


The Loader Servlet

The "Loader Servlet" is a special servlet included with the distribution that can load servlets, given only the classname. It searches the path specified by an initialization parameter. For example:

Loader.mapping=/servlet/Loader/*
Loader.class=com.qindesign.servlet.LoaderServlet
Loader.initParams=classpath=/web/servlet/classes

For the above specification, the servlet will search the default and user classpaths, and then /web/servlet/classes for a given classname. Notice how the search classpath is specified. It is a servlet initialization parameter named "classpath".

Further details about the "/*" at the end of the mapping can be found in the Servlet 2.2 Specification, but in short, it allows extra information to be passed to the servlet in the form of a path. This is called the "Path Info" part of the request.

[Motivation: The Path Info specifies the classname of the servlet to load, and any parameters are passed to the servlet as normal. This is the motivation for using the Path Info for the servlet. It allows the parameters to be passed untouched.

For example, if we use the above mapping, this request (note that the line may be wrapped, but should be on one line):

/servlet/Loader/com.qindesign.servlet.example.RequestInfoServlet?param1=value1&param2=value2

will call the com.qindesign.servlet.example.RequestInfoServlet servlet with param1 and param2 as parameters. ]

Lastly, for each requested servlet, a new instance is always created, and the servlet goes through its entire lifecycle, from init to destroy.

[Top]


Summary

In summary, here are the things you need to do to take advantage of Tynamo™'s servlet reloading capabilities:

  1. Ensure reloading is turned on via a value of true for the servlet.reloadingEnabled configuration property.
  2. Take care that your servlets are mentioned in the servlet configuration file.
  3. Specify the location of your classes in the servlet.classpath property.

To take advantage of the Loader Servlet, follow these steps:

  1. Properly configure the Loader Servlet in the servlet configuration file.

[Top]