On 4/12/2010 1:29 PM, Jason von Nieda wrote:
Hi all,

These actions, even after the proper Derby shutdown procedures cause the classloader to not be unloadable. Can someone take a look at the code below and tell me if I am missing something, or is this perhaps a known issue?
The important thing I think is to shutdown using the same class loader in which Derby is booted. Below are some code snippets to do this. I recently checked in a change to 10.6 that shows the class loader for boot and shutdown. I'll be backporting that soon to 10.5. The problem I have mostly seen with using the wrong class loader to shutdown is that a subsequent boot attempt fails.





If you don't have direct access to the class loader, you can get it from the connection with getClassLoader()

e.g.

    shutdownWithLoader(conn.getClass().getClassLoader());



private static void shutdownWithLoader(ClassLoader loader) throws Exception {
    DataSource ds = newDataSource(loader,"");
    Class[] argType = {String.class};
    String[] args = new String[] {"shutdown"};
    Method sh = ds.getClass().getMethod("setShutdownDatabase", argType);
    sh.invoke(ds, (Object[]) args);

    try {
        ds.getConnection();
    }catch (SQLException se ) {
        if (se.getSQLState().equals("XJ015")) {
        System.out.println("Normal Shutdown");
        }
        else
        throw se;
    }

    }



private static DataSource newDataSource(ClassLoader loader, String databaseName) throws Exception
    {
DataSource ds = (DataSource) loader.loadClass("org.apache.derby.jdbc.EmbeddedDataSource").newInstance();
        // setDatabaseName with reflection
        Class[] argType = {String.class};
        String[] args = new String[] {databaseName};
        Method sh = ds.getClass().getMethod("setDatabaseName", argType);
        sh.invoke(ds, (Object[]) args);
        return ds;

    }


Reply via email to