4
votes

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?
1

1 Answers

6
votes

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.