Re: Shutdownhook not working

From: G (news_at_gweb.be)
Date: 11/22/04

  • Next message: Murray: "Re: Shutdownhook not working"
    Date: Mon, 22 Nov 2004 17:31:58 +0100
    
    

    " I restart the servlet the connections seem not to close"
    How do you restart ?
    Did you shut down the JVM ? ShutdownHook are only invoked when JVM shuts
    down and, if the JVM shuts down, db connections should be closed
    implicitelly, so you shouldn't see connections in the database console ...

    Try to place a breakpoint in you method ...

    "Jonck" <jonck@vanderkogel.net> wrote in message
    news:20041122164653115+0100@news.text.chello.nl...
    > Hi all,
    > A web application (using servlets) that I wrote connects to a database
    > and stores the headers and data sent along with the HttpServletRequest.
    > To make the interaction faster, when the servlet is initialized I create
    > a pool of objects, each of which maintains a Connection to a MySQL
    > database. I use a shutdownhook to close the connections, as I was told
    > that this was the safest way. In the init() part of the servlet I put
    > the following code, to close the connection:
    >
    > Runtime runTime = Runtime.getRuntime();
    > ShutDownObject hook = new ShutDownObject(processors);
    > runTime.addShutdownHook(new Thread(hook));
    >
    > The shutdown object is as follows:
    >
    > public class ShutDownObject implements Runnable {
    > private Vector toolboxPool;
    > /** Creates a new instance of ShutDownObject */
    > public ShutDownObject(Vector pool) {
    > toolboxPool = pool;
    > } }
    >
    > public void run() {
    > Iterator poolIterator = toolboxPool.iterator();
    > while (poolIterator.hasNext()) {
    > try {
    > ((ToolboxUnit) poolIterator.next()).getDbConnection().disconnect();
    > } } catch (SQLException e) {
    > System.out.println(e.getMessage());
    > } }
    > } }
    > } }
    > }
    >
    > So as you can see in the run() section I iterate my pool of db
    > connections and close them. But for some reason, whenever I restart the
    > servlet the connections seem not to close. The way I'm checking this is
    > in the MySQL terminal I check the number of connected threads:
    > mysql> show status like "Threads_connected";
    >
    > If, for example, I create a pool of 10 objects, after restarting the
    > servlet the number of threads connected will be 10 larger than before
    > the servlet was restarted.
    >
    > Could anyone tell me what I'm doing wrong?
    >
    > Thanks very much, Jonck


  • Next message: Murray: "Re: Shutdownhook not working"

    Relevant Pages

    • Re: SBS Exchange 2003: too many "Current Sessions" opened
      ... Since exchange defaults to accepting ... IF, after a week, you are still seeing some connections, try *DISABLING* ... SenderID filtering on the Virtual SMTP server. ... You do *not* need to restart the server, ...
      (microsoft.public.windows.server.sbs)
    • Re: Best practice for initializing JDBC connection in Servlets.
      ... > access the servlet simultaneously? ... initialize the JDBC driver in initand manage connections in doGet. ...
      (comp.lang.java.programmer)
    • Re: servlets slow when disconnected
      ... You really should read the servlet spec. ... the servlet container is the software that provides the context ... If the network interface is actually shut down at the OS level then the ... You especially want that for wireless connections. ...
      (comp.lang.java.programmer)
    • Re: iMac G5 crashes on restart & wake from sleep...
      ... A similiar problem happens sometimes when I restart ... I believe the problems might be linked to USB ... My current USB connections are keyboard/mouse, ... Now that Pentium D in that HP I tried out wasn't too bad, but it was quite a bit more noisy than this G5, but when I first turned on the HP the machine sounded like a turbine spinning up. ...
      (comp.sys.mac.advocacy)
    • Re: iMac G5 crashes on restart & wake from sleep...
      ... A similiar problem happens sometimes when I restart ... the problems disappear when I unplug all USB devices except the ... My current USB connections are keyboard/mouse, ... quite a bit more noisy than this G5, but when I first turned on the HP ...
      (comp.sys.mac.advocacy)