简体   繁体   中英

how to use cassandra session for multiple threads?

I am using cassandra as backend in web application(in java), where for each user need to create unique session or use single one as in below url?

I read session information in this link. https://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/Session.html

Its saying Session instances are thread-safe. Means one thread at a time can use this instance.

Also written that each session maintains multiple connections to the cluster nodes.

Question is

  1. if only one thread can use on session instance then what is use of creating multiple connection per session to the cluster nodes?
  2. Doesn't it slow downs multithread operations on session?

You got it wrong, it is safe to share an instance with different threads:

A session holds connections to a Cassandra cluster, allowing it to be queried. Each session maintains multiple connections to the cluster nodes...

Session instances are thread-safe and usually a single instance is enough per application.

Thread-safe means that it is safe to share the instance with other threads. It does not mean that you can only use it from a single one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM