db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Piet Blok" <pbh...@wanadoo.nl>
Subject Re: Database shutdown
Date Thu, 12 May 2005 15:27:54 GMT

Incidentally yesterday, when reading the new pdf manuals, I found out about 
database shutdown, so I tried to implement it. From a shutdown hook I call 
the following method:

    protected void shutdown() {
        Properties shutdownProperties = new Properties();
        shutdownProperties.put("shutdown", "true");
        try {
            driver.connect("jdbc:derby:", shutdownProperties);
        } catch (SQLException e) {
            if (e.getErrorCode() == 50000) {
            } else {


This works (up to now) perfectly. I believe the mistake you make is adding 
the database name to the connection URL. In the above code "driver" refers 
to an EmbeddedDriver instance, created like this:

    private EmbeddedDriver driver = new EmbeddedDriver();

>From this driver I obtained connections using, ofcourse, a database name.

Kind regards,

Piet Blok

----- Original Message ----- 
From: "Andrew Shuttlewood" <andrew.shuttlewood@futureroute.co.uk>
To: <derby-user@db.apache.org>
Sent: Thursday, May 12, 2005 4:29 PM
Subject: Database shutdown

> We have a shutdown hook registered to close down our derby databases,
> but every so often, even when the shutdown hook triggers, we find that
> it spends a lot of time in LogToFile.recover
> Our shutdown hook looks something like
>        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable(){
>            public void run() {
>                try {
>                    Log.log(Level.INFO, "Attempting shutdown of Embedded
> Core Driver.");
>                    DriverManager.getConnection("jdbc:derby:" +
> Foo.this.databaseName + ";shutdown=true");
>                } catch (SQLException e) {
>                    System.out.println("Shutdown: " +
> Foo.this.databaseName);
>                    Log.log(Level.INFO, "Embedded Core Driver Shut
> Down", e);
>                }
>            }
>        }));
> This seems to do the right thing (sort of), but it doesn't always seem
> to work. Am I missing something? Is a shutdown hook the absolutely wrong
> place to do this? Am I perhaps making a obvious mistake?
> I can't really see the problem which is very frustrating!
> Also, in terms of memory usage, is it possible to reduce the amount of
> memory used by all instances to some degree as we may wish to use a
> number of instances at any one time. I was planning on potentially using
> SoftReferences to manage a database pointer and then "shutting down" as
> necessary, but I would quite like it if there was a way of setting a
> global max number of pages or some such. Is this possible?

View raw message