Processing future results

After executing query results, we may want to process the results of those queries. This can be done by creating an array of ResultSetFuture and looping through the array and calling future methods to get ResultSet. For the earlier query, you could do something like this:

ArrayList<ResultSetFuture> futures = new ArrayList<ResultSetFuture>();for (int i=0; i< 500; i++) { // 500 inserts at a time futures.add( insertUserData(/*.. User data */ ) );}for (ResultSetFuture future : futures) { // Process future resultsfuture.getUninterruptibly();}

First, we instantiate an empty array called futures to store the ResultSetFuture objects.

In the first loop, we execute the insertUserData() method 500 times and add the result ...

Get Learning Apache Cassandra - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.