DB connection opening/closing


In the Java bindings, what is the correct usage of the Database object in terms of opening and closing it?

The class scheduler example does once, and uses it for the whole example. Some third party examples I’ve seen open/close it once per operation (I assume this is expensive).

If my app only opens it once, is it capable of handling multiple concurrent requests? Does it reconnect itself if the connection dies? Or is this meant to be handled at the app level?

(A.J. Beamon) #2

The recommended behavior is to keep a Database open and reuse it for as long as you need it. I don’t think opening multiple Databases for the same cluster provides any advantages (unless you need to be able to set different database-level options), and opening them does have a cost, particularly if you are doing it for every transaction.

A single Database will be able to handle multiple concurrent requests, and it will try to reconnect if a connection fails.