cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Soika <>
Subject Cassandra DataStax Java Driver in combination with Java EE / EJBs
Date Tue, 11 Jun 2019 21:38:16 GMT

I have a question concerning the Cassandra DataStax Java Driver in 
combination with Java EE and EJBs.

I have implemented a Rest Service API based on Java EE8. In my 
application I have for example a jax-rs rest resource to write data into 
cassandra cluster. My first approach was to create in each method call

 1.   a new Casssandra Cluster and Session object,
 2.   write my data into cassandra
 3.   and finally close the session and the cluster object.

This works but it takes a lot of time (2-3 seconds) until the cluster 
object / session is opened for each request.

  So my second approach is now a @Singleton EJB providing the session 
object for my jax-rs resources. My service implementation to hold the 
Session object looks something like this:

*public class* ClusterService {
     private Cluster cluster;
     private Session session;

*private void* init() throws ArchiveException {
         session = initArchiveSession();

*private* void tearDown() throws ArchiveException {
         // close session and cluster object
         if (session != null) {
         if (cluster != null) {

*public* Session getSession() {
         if (session==null) {
             try {
             } catch (ArchiveException e) {
                 logger.warning("unable to get falid session: " + 
*return* session;



And my rest service calls now looking like this:

*public class* ArchiveRestService {

     ClusterService clusterService;

     @Consumes({ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
*public* Response postData(XMLDocument xmlDocument) {
         Session session = clusterService.getSession();

The result is now a super-fast behavior!Seems to be clear because my 
rest service no longer need to open a new session for each request.

My question is: Is this approach with a @Singleton ClusterService EJB 
valid or is there something I should avoid?
As far as I can see this works pretty fine and is really fast. I am 
running the application on a Wildfly 15 server which is Java EE8.

Thanks for your comments



*Imixs Software Solutions GmbH*
*Web:* <> *Phone:* +49 (0)89-452136 16
*Office:* Agnes-Pockels-Bogen 1, 80992 München
Registergericht: Amtsgericht Muenchen, HRB 136045
Geschaeftsführer: Gaby Heinle u. Ralph Soika

*Imixs* is an open source company, read more: 

View raw message