Oops, how embarrassing. Just after sending the email I tried yet another Google 
search and found the answer here:

https://cwiki.apache.org/confluence/display/empiredb/Frequently+asked+questions#Frequentlyaskedquestions-ShouldDBDatabasebereopenedoneveryconnectionoritisenoughtoopenitonlyonce?

Yet, the Javadoc seems to contradict the FAQ in that it says about open(): 
"This will set up the connection for use".

May I suggest to change the wording for open() to something like:

Sets the database driver for this database. The connection is used by some 
drivers during their initialization, but it is not stored either in the driver 
or in {@code this} and may be closed after this call.

A similar hint as of the transient nature of the connection object for the 
operation applies, I reckon, to the close() method. In particular the 
connection object passed to close needs not be the same as the one passed to 
open() (?)

Regards,
Harald.
________________________________________
Von: Harald Kirsch <[email protected]>
Gesendet: Samstag, 18. Oktober 2014 17:47
An: [email protected]
Betreff: DBDatabase object usable by multiple threads

Looking at the implementation of open() in DBDatabase, it does not look like 
this is thread save, because whichever thread happens to be last, wins in 
opening the database for its combination of DBDatabaseDriver and JDBC 
Connection.

Does this mean that in a typical WEB application each request needs it own 
DBDatabase object which, when not working with sessions needs to be created 
from scratch for each request?

As explained in the tutorial, I derive my db schema from DBDatabase and add the 
tables by creating them in the constructor. This is (a) non trival code and (b) 
always creates the exact same object again, so it seems a bit of a waste to 
perform the creation over and over again.

Clearly I am missing something. Is DBDatabase thread safe nevertheless?

Regards,
Harald.

Reply via email to