This document is DEPRECATED.

Please consider any information here as out of date. DO NOT use this document.

Instead, refer to

Please update your bookmarks accordingly.

Skip to end of metadata
Go to start of metadata

In addition to synchronous API methods like Cache.put(), Cache.remove(), etc., Infinispan also has an asynchronous, non-blocking API where you can achieve the same results in a non-blocking fashion.

These methods are named in a similar fashion to their blocking counterparts, with "Async" appended.  E.g., Cache.putAsync(), Cache.removeAsync(), etc.  These asynchronous counterparts return a Future containing the actual result of the operation.

For example, in a cache paramerized as Cache<String, String>, Cache.put(String key, String value) returns a String.  Cache.putAsync(String key, String value) would return a Future<String>.

Why use such an API?

Non-blocking APIs are powerful in that they provide all of the guarantees of synchronous communications - with the ability to handle communication failures and exceptions - with the ease of not having to block until a call completes.  This allows you to better harness parallelism in your system.  For example:

Which processes actually happen asynchronously?

There are 4 things in Infinispan that can be considered to be on the critical path of a typical write operation.  These are, in terms of cost, network calls, marshalling, writing to a cache store (optional), and locking.  As of Infinispan 4.0, using the async methods will take the network calls and marshalling off the critical path.  For various technical reasons, writing to a cache store and acquiring locks, however, still happens in the caller's thread.  In future, we plan to take these offline as well.  See this developer mail list thread about this topic.

Notifying futures

Strictly, these methods do not return JDK Futures, but rather a sub-interface known as a NotifyingFuture.  The main difference is that you can attach a listener to a NotifyingFuture such that you could be notified when the future completes.  Here is an example of making use of a notifying future:

Further reading

The Javadocs on the Cache interface has some examples on using the asynchronous API, as does this article by Manik Surtani introducing the API.

datagrid datagrid Delete
infinispan infinispan Delete
data_grid data_grid Delete
non-blocking non-blocking Delete
async async Delete
api api Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.