1 Reply Latest reply on Jan 8, 2015 7:20 AM by Kohei Nozaki

    Is there a way to properly shutdown of Embedded Derby in WildFly?

    Kohei Nozaki Newbie

      Hello,

       

      I registered a DataSource of Embedded Derby in WildFly8.0.0CR1,

      and noticed that Derby's db.lck file remained after shutdown of WildFly.

      so I guess I need to configure WildFly to execute shutdown procedure of Derby.


      so I tried to deploy a MBean that executes DriverManager.getConnection("jdbc:derby:;shutdown=true");

      but it didn't helps. I saw a SQLException and it didn't make db.lck file disappear. like that:


      17:39:04,115 ERROR [stderr] (ServerService Thread Pool -- 59) java.sql.SQLException: No suitable driver found for jdbc:derby:;shutdown=true

      17:39:04,115 ERROR [stderr] (ServerService Thread Pool -- 59) at java.sql.DriverManager.getConnection(DriverManager.java:596)

      17:39:04,115 ERROR [stderr] (ServerService Thread Pool -- 59) at java.sql.DriverManager.getConnection(DriverManager.java:233)

      17:39:04,115 ERROR [stderr] (ServerService Thread Pool -- 59) at articles.ejb.DerbyShutdownEJB.preDestroy(DerbyShutdownEJB.java:18)

      17:39:04,116 ERROR [stderr] (ServerService Thread Pool -- 59) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      17:39:04,116 ERROR [stderr] (ServerService Thread Pool -- 59) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

      ...

       

      And I noticed that my MBean ran after below message so I guess that my MBean lost chance to shutdown

      because JDBC driver was already unloaded.

       

           17:39:04,097 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-4) JBAS010409: Unbound data source [java:jboss/datasources/DerbyDS2]

       

      And my MBean couldn't found any Derby Driver at all. I tried invoke getDrivers() but it always returned empty collection.


      So Is there a way to properly shutdown of Embedded Derby in WildFly?


      my MBean code and logs are below (sorry for dirty implementation):


      public class DerbyShutdownService implements DerbyShutdownServiceMBean {

        private String message = "Sorry no message today";

       

        @Override

        public String getMessage() {

        return message;

        }

       

        @Override

        public void setMessage(String message) {

        this.message = message;

        }

       

        @Override

        public void printMessage() {

        System.out.println(message);

        }

       

        public void driver(ClassLoader cl) throws Exception{

        System.out.println(cl);

        Class c= cl.loadClass("java.sql.DriverManager");

        Method m = c.getMethod("getDrivers");

        Object o = m.invoke(null);

        Enumeration e2 = (Enumeration)o;

        System.out.println(e2.hasMoreElements());

        if(e2.hasMoreElements()){

        System.out.println(e2.nextElement());

        }

        }

       

        public void hogehoge() throws Exception{

        Enumeration e = DriverManager.getDrivers();

        System.out.println(e);

        System.out.println(e.hasMoreElements());

        if(e.hasMoreElements()){

        System.out.println(e.nextElement());

        }

       

        driver(DerbyShutdownService.class.getClassLoader().getParent());

        driver(DerbyShutdownService.class.getClassLoader().getParent().getParent());

        driver(DerbyShutdownService.class.getClassLoader().getSystemClassLoader());

        }

       

        public void start() throws Exception {

        System.out.println(">>>>Starting with message=" + message);

        hogehoge();

        }

       

        public void stop() throws Exception {

        System.out.println(">>>>Stopping with message=" + message);

        hogehoge();

        }

      }

       

      17:39:04,097 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-4) JBAS010409: Unbound data source [java:jboss/datasources/DerbyDS2]

      17:39:04,098 INFO  [stdout] (MSC service thread 1-7) >>>>Stopping with message=Hello

      17:39:04,098 INFO  [stdout] (MSC service thread 1-7) java.util.Vector$1@e312ac7

      17:39:04,099 INFO  [stdout] (MSC service thread 1-7) false

      17:39:04,099 INFO  [stdout] (MSC service thread 1-7) sun.misc.Launcher$AppClassLoader@4821e115

      17:39:04,099 INFO  [stdout] (MSC service thread 1-7) false

      17:39:04,099 INFO  [stdout] (MSC service thread 1-7) sun.misc.Launcher$ExtClassLoader@28404eb2

      17:39:04,100 INFO  [stdout] (MSC service thread 1-7) false

      17:39:04,100 INFO  [stdout] (MSC service thread 1-7) sun.misc.Launcher$AppClassLoader@4821e115

      17:39:04,100 INFO  [stdout] (MSC service thread 1-7) false

      17:39:04,105 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-10) JBAS010418: Stopped Driver service with driver-name = derby.jar