You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Karl Weber <ka...@googlemail.com> on 2012/02/18 15:45:49 UTC

Shutdown DB does not work / threadding issue

Hi,

I am using Derby DB in an embedded environment. I am shutting down the DB and 
the system using the following two methods (I have ommitted all try-catch-
finally stuff, logging etc.)

Shutting down the DB, where fDS is an EmbeddedDataSource40:

public void shutdownDB() {
	fDS.setShutdownDatabase("shutdown");
	fDS.getConnection().close();
}

Shutting down the system:

public void shutdownDerby() {
	DriverManager.getConnection("jdbc:derby:;shutdown=true");
}

This works, if it is done on the thread that is shutting down my OSGi 
component, which encapsulates Derby, i.e. the deactivate-method called by the 
OSGi framework. This does, however, _not_ work, if it is put in a separate 
thread in the deactivate-method, as in

new Thread(new Runnable() {
	@Override
	public void run() {
		shutdownBD();
		shutdownDerby();
	}
}).start();

In this case, the Runnable stops at the statement

fDS.getConnection().close();

No Throwable is thrown. Nevertheless, the DB does not seem to be stopped 
correctly, as in the latter case (only) I find the two files dbex.lck and 
db.lck in the DB folder. 

Right before this "last" statement is called, I have around 12 threads 
running, so the thread running the Runnable will most probably not be the last 
thread in the JVM, if that matters.

For some reason I would like to shutdown things asynchroneously. What do I 
miss here?

I am using Derby 10.8.2.2.

/Karl

Re: Shutdown DB does not work / threadding issue

Posted by Karl Weber <ka...@googlemail.com>.
Am Montag, 20. Februar 2012, 08:44:58 schrieb Kristian Waagan:
> When you say stops, do you mean the thread is blocking/hanging?
> If so, can you obtain a stack trace?

No, it seems to be terminated somehow before the shutdown operation can be 
finished. When I put a Thread.sleep(250) after the new Thread(...).start(), it 
works. When I make the time smaller, i.e. sleep(200), the shutdown is 
incomplete again.

Hence, it does not seem to be a problem of derby, but of my application. But 
anyway, I am surprised, I thought every thread will have a chance to finish 
before the JVM terminates. I have no idea, why this is not the case.

Re: Shutdown DB does not work / threadding issue

Posted by Kristian Waagan <kr...@oracle.com>.
On 18.02.2012 15:45, Karl Weber wrote:
> Hi,
>
> I am using Derby DB in an embedded environment. I am shutting down the DB and
> the system using the following two methods (I have ommitted all try-catch-
> finally stuff, logging etc.)
>
> Shutting down the DB, where fDS is an EmbeddedDataSource40:
>
> public void shutdownDB() {
> 	fDS.setShutdownDatabase("shutdown");
> 	fDS.getConnection().close();
> }
>
> Shutting down the system:
>
> public void shutdownDerby() {
> 	DriverManager.getConnection("jdbc:derby:;shutdown=true");
> }
>
> This works, if it is done on the thread that is shutting down my OSGi
> component, which encapsulates Derby, i.e. the deactivate-method called by the
> OSGi framework. This does, however, _not_ work, if it is put in a separate
> thread in the deactivate-method, as in
>
> new Thread(new Runnable() {
> 	@Override
> 	public void run() {
> 		shutdownBD();
> 		shutdownDerby();
> 	}
> }).start();
>
> In this case, the Runnable stops at the statement
>
> fDS.getConnection().close();

Hi,

When you say stops, do you mean the thread is blocking/hanging?
If so, can you obtain a stack trace?


Regards,
-- 
Kristian

>
> No Throwable is thrown. Nevertheless, the DB does not seem to be stopped
> correctly, as in the latter case (only) I find the two files dbex.lck and
> db.lck in the DB folder.
>
> Right before this "last" statement is called, I have around 12 threads
> running, so the thread running the Runnable will most probably not be the last
> thread in the JVM, if that matters.
>
> For some reason I would like to shutdown things asynchroneously. What do I
> miss here?
>
> I am using Derby 10.8.2.2.
>
> /Karl