empire-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Harald Kirsch <harald.kir...@raytion.com>
Subject AW: DBDatabase object usable by multiple threads
Date Sat, 18 Oct 2014 16:00:07 GMT
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 <harald.kirsch@raytion.com>
Gesendet: Samstag, 18. Oktober 2014 17:47
An: user@empire-db.apache.org
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.


Mime
View raw message