db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Albert Kam" <moonblade.w...@gmail.com>
Subject Re: Shutdown cleanly embedded derby when tomcat shutdown ?
Date Fri, 11 Jul 2008 08:21:42 GMT
Dear all ..

Ah, finally, a solution that works !

I use this resource in the webapps/mywebapp/META-INF/context.xml to shutdown
derby (so in the context.xml, i got 2 datasources, 1 is the normal
datasource, and this one is to shut derby down):

        <Resource name="jdbc/SofcoSMSShutdown" auth="Container"
              maxActive="1" maxIdle="30" maxWait="10000"
              username="app" password="a"

I just need to add this in the web.xml
      <description>Shutdown SofcoSMS DataSource</description>

and use it in the source code like this :
    public void shutdownDB() {
        Context initCtx;
        try {
            log.debug("shutting down database from datasource");
            initCtx = new InitialContext();
            Context envCtx = (Context) initCtx.lookup("java:comp/env");
            ds = (DataSource) envCtx.lookup("jdbc/SofcoSMSShutdown");
            ds = null;
            log.debug("database shutdown complete");
        } catch (NamingException e) {
            throw new InfrastructureException(e);
        } catch (SQLException e) {
            throw new InfrastructureException(e);

Also, i put the shutting down process in the apache struts' plugin mechanism
in the destroy() method which will be called when the webapp is being
unloaded by the servlet container.

It works like charm !

Anyway i tried the :

But it didnt succeed as i got a ClassCastException just as depicted in this
thread :

Also, one note for others who get this 'tomcat-hanging or lingering after
shutdown' issue that i found on the web is that to use "kill -3
<tomcat-pid>", and then check the catalina.out for the threads that still
linger. Very helpful in identifying what that we forget to close.

Albert Kam

Do not pursue the past. Do not lose yourself in the future.
The past no longer is. The future has not yet come.
Looking deeply at life as it is in the very here and now,
the practitioner dwells in stability and freedom.
(Thich Nhat Hanh)

View raw message