Re: Shutdownhook not working
From: G (news_at_gweb.be)
Date: 11/22/04
- Previous message: G: "Symbolic lin"
- In reply to: Jonck: "Shutdownhook not working"
- Next in thread: Murray: "Re: Shutdownhook not working"
- Reply: Murray: "Re: Shutdownhook not working"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: G: "Symbolic lin"
- In reply to: Jonck: "Shutdownhook not working"
- Next in thread: Murray: "Re: Shutdownhook not working"
- Reply: Murray: "Re: Shutdownhook not working"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|