user1730177
user1730177

Reputation: 91

how to run asynchronous queries with Spring

I need to use asynchronous queries using Spring framework. I use Cassandra and Java driver from Datastax. How can call the executeAsync method and get the results.

Upvotes: 2

Views: 1582

Answers (1)

Nenad Bozic
Nenad Bozic

Reputation: 3784

I have in mind 3 possible solutions:

  1. executeAsync returns ResultSetFuture which has isDone method, you can have while loop with!isDoneand jump to some block when it returnstrueinisDone`
  2. There is addListener in ResultSetFuture so you can register listener to be fired after Future computation is done

Registers a listener to be run on the given executor. The listener will run when the Future's computation is complete or, if the computation is already complete, immediately.

  1. You can try similar approach but using ListenableFuture from the Guava library since which ResultSetFuture extends like explained in this stackoverflow question

I think 3rd option is way to go and cleanest.

Upvotes: 2

Related Questions