using prepared statement multiple times, giving a warning of Cassandra Querying Reducing Performance

蹲街弑〆低调 提交于 2019-11-27 16:28:56

Calling prepare Everytime is not a good idea..to avoid that you can simply keep a map of query string vs prepared statements..you can fill the cache at startup only hence prepare will be called only once ...now in your Cassandrautil methoda you will get prepared statement from map and create the bound statement and execute it.

Datastax document already states that

You should prepare only once, and cache the PreparedStatement in your application (it is thread-safe). If you call prepare multiple times with the same query string, the driver will log a warning.

If you execute a query only once, a prepared statement is inefficient because it requires two roundtrips. Consider a simple statement instead.

Java Driver for Apache Cassandra 3.1 (Earlier version) you can check for specific version.

Cashing prepared statement is what is recommended for your application. For that ConcurrentHashMap is good alternate and keep using it (PreparedStatement) as said in the document it is THREAD SAFE. I hope same implementation is provided for scala as well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!