Datastax - Prepared by Statement Stream Safe?

Should an instance of com.datastax.driver.core.PreparedStatement be single in the application?

If so, what happens if the connection is lost? Is PreparedStatement invalid and must a manual action be taken to β€œredo it”?

A simple example of using PreparedStatement (other than preparing + execution in the same method) would be brilliant!

+7
source share
1 answer

PreparedStatement objects are thread safe. You can mutate them (for example, set the default level of consistency) in ways that can lead to inconsistency if several threads did this at the same time, but it has no analogues.

Prepared statements are basically wrappers around identifier and metadata, and the server will support the prepared statement until it gets up (but a failure or restart of the node means that it is lost and must be representative). Theoretically prepared statement can be serialized and deserialized elsewhere and still working, a bit I would not recommend it.

The prepared statements are local to the node, and, as I already mentioned, do not survive reboots, so if you are going to support them, you need to be sure that you clear them when the connections fail or restart the nodes. I would try to cover them as well as your connections, recreate them when connecting and reconnecting. This may not be great advice, but it depends on how your application is structured.

+8
source

All Articles