.....
Statement select = QueryBuilder.select().all().from(keyspace, tableName).where(QueryBuilder.eq("id", id)).and(QueryBuilder.eq("version", version));
ResultSet results = CassandraManager.execute(select);
.....
And this is the CassandraManager class that I'm using:
package com.db.main;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ScheduledExecutorService;
import com.datastax.driver.core.BoundStatement;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.PagingState;
import com.datastax.driver.core.PoolingOptions;
import com.datastax.driver.core.PreparedStatement;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.Statement;
import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.plugg.system.RuntimeProperties;
import com.plugg.system.Timer;
public class CassandraManager {
private static PoolingOptions poolingOptions;
private static Cluster cluster;
private static Session session;
private static boolean FORCE_DEBUG = false;
private static ScheduledExecutorService scheduled;
private synchronized static void Init() throws Exception {
poolingOptions = new PoolingOptions();
cluster = Cluster
.builder()
.addContactPoints(RuntimeProperties.getSystemProperties().cassandraHost)
.withPoolingOptions(poolingOptions)
.build();
session = cluster.connect();
}
private synchronized static Session getSession() throws Exception {
if(cluster==null) {
CassandraManager.Init();
}
return session;
}
public synchronized static BoundStatement getBoundStatement(String query) throws Exception {
PreparedStatement statement = getSession().prepare(query);
return new BoundStatement(statement);
}
public synchronized static ResultSet execute(String query, boolean debug) throws Exception {
ResultSet res = null;
if(debug || FORCE_DEBUG) {
Timer.Start();
Session sess = getSession();
Timer.Stop();
long eOne = Timer.getElapsedMilliseconds();
Timer.Stop();
res = sess.execute(query);
Timer.Stop();
long eTwo = Timer.getElapsedMilliseconds();
System.out.println("Session in "+eOne+"ms; Executed in: "+eTwo+"ms; "+query);
} else {
res = getSession().execute(query);
}
return res;
}
public synchronized static ResultSet execute(Statement statement, boolean debug) throws Exception {
ResultSet res = null;
if(debug || FORCE_DEBUG) {
Timer.Start();
Session sess = getSession();
Timer.Stop();
long eOne = Timer.getElapsedMilliseconds();
Timer.Stop();
res = sess.execute(statement);
Timer.Stop();
long eTwo = Timer.getElapsedMilliseconds();
System.out.println("Session in "+eOne+"ms; Executed in: "+eTwo+"ms; "+statement.toString());
} else {
res = getSession().execute(statement);
}
return res;
}
public synchronized static void Close() {
if(scheduled!=null) {
scheduled.shutdown();
}
if(session!=null) {
session.close();
}
if(cluster!=null) {
cluster.close();
}
}
public synchronized static UUID generateId() {
return UUID.randomUUID();
}
}
--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-user+unsubscribe@lists.datastax.com.
Session is thread safe so you're doing extra work here for no benefit, ideally you set the call to init() in an initializer and then can avoid all of the other synchronization calls
Anyway your execute call is the big culprit here and literally your telling java to have only one thread access execute() at once which is the behavior you're describing.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.
--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.
I'm sorry I posted such a stupid question! This was definitely not a C* problem, I cannot believe I didn't see all the functions were "synchronized"! removed it...everything is fine.Thanks a lot for your help!
--