Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

Tomcat and HTTPServlet destroy Problem

Thread view: 
Marko Langbein - 17 Jun 2005 13:19 GMT
Hi,

i run an tomcat 5.5.9 and jdk-1_5_0_03-windows-i586-p.

I'm write an small test HttpServlet (with init/destroy), wich on-loaded
through web.xml at starttime. The init function correctly called by tomcat.

But uf i close tomcat, the destroy function do not called:

----------------snips from servlet code
public class Controller extends  HttpServlet {
   Logging log;

   public void init() throws ServletException {
      super.init();
      buildController();
      return;
   }

   private void buildController() {
      log = new Logging();
      log.log("start");
   }

   public void destroy() {
      try {
    log.log("end");
      } catch (Exception e) {
      }
      return;
   }
}
----------------snips from servlet code

Have somebody same problems or can verify my problem?

best regards
Marko Langbein
Alan Krueger - 18 Jun 2005 03:34 GMT
> But uf i close tomcat, the destroy function do not called:
>
> ----------------snips from servlet code
[...]

>    public void destroy() {
>       try {
[quoted text clipped - 7 lines]
>
> Have somebody same problems or can verify my problem?

Put a log statement in that catch and see if an exception is being
thrown.  Also put a log statement in init() to be sure it's being called
properly.
Marko Langbein - 20 Jun 2005 14:25 GMT
>> But uf i close tomcat, the destroy function do not called:
>>
[quoted text clipped - 16 lines]
> Put a log statement in that catch and see if an exception is being
> thrown.
No exception :(
> Also put a log statement in init() to be sure it's being called
> properly.
Yeah - init() works correctly.

I think, this is a little bit beta version of tomcat :(

Regards
marko
Alan Krueger - 20 Jun 2005 15:50 GMT
> Yeah - init() works correctly.
> I think, this is a little bit beta version of tomcat :(

On that note, what version?  How are you launching and closing Tomcat?
Marko Langbein - 21 Jun 2005 11:04 GMT
>> Yeah - init() works correctly.
>> I think, this is a little bit beta version of tomcat :(
>
> On that note, what version?  
This: jakarta-tomcat-5.5.9.tar.gz
> How are you launching and closing Tomcat?
startup.bat and shutdown.bat ....

Greetings
marko
Alan Krueger - 21 Jun 2005 23:46 GMT
>> On that note, what version?  
>
> This: jakarta-tomcat-5.5.9.tar.gz
>
>  > How are you launching and closing Tomcat?
> startup.bat and shutdown.bat ....

The following class (based on your post) with the following web.xml
produce the following log for me on Tomcat 5.5.9 under Windows XP.

I performed the following set of operations:
    - start Tomcat
    - access servlet
    - stop Tomcat
    - start Tomcat
    - stop Tomcat

Note the corresponding start/end log entries.

How are you testing your version of this class?  Can you post something
compilable and a copy of your web.xml?

---begin Controller.java---
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.*;

public class Controller extends HttpServlet {
    public void init() throws ServletException {
        super.init();
        buildController();
    }
    private void buildController() {
        log( "start" );
    }
    protected void service(
            HttpServletRequest req,
            HttpServletResponse resp )
            throws ServletException, IOException {
        log( "service" );
    }
    public void destroy() {
        try {
            log( "end" );
        } catch ( Exception e ) {
            log( e.getMessage() );
        }
    }
}
---end Controller.java---

---begin web.xml---
<!DOCTYPE web-app PUBLIC
    "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
    <servlet>
        <servlet-name>Controller</servlet-name>
        <servlet-class>Controller</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Controller</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>
---end web.xml---

---begin log---
Jun 21, 2005 5:26:56 PM org.apache.catalina.core.ApplicationContext log
INFO: Controller: start
Jun 21, 2005 5:26:58 PM org.apache.catalina.core.ApplicationContext log
INFO: Controller: service
Jun 21, 2005 5:27:04 PM org.apache.catalina.core.ApplicationContext log
INFO: Controller: end
Jun 21, 2005 5:32:04 PM org.apache.catalina.core.ApplicationContext log
INFO: Controller: start
Jun 21, 2005 5:32:13 PM org.apache.catalina.core.ApplicationContext log
INFO: Controller: end
---end log---


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.