JBoss.orgCommunity Documentation

Chapter 4. Batching API

4.1. Introduction
4.2. Configuring batching
4.3. Batching API

The batching API, introduced in JBoss Cache 3.x, is intended as a mechanism to batch the way calls are replicated independent of JTA transactions.

This is useful when you want to batch up replication calls within a scope finer than that of any ongoing JTA transactions.

To use batching, you need to enable invocation batching in your cache configuration, either on the Configuration object:


or in your XML file:

   <invocationBatching enabled="true"/>

By default, invocation batching is disabled. Note that you do not have to have a transaction manager defined to use batching.

Once you have configured your cache to use batching, you use it by calling startBatch() and endBatch() on Cache. E.g.,

   Cache cache = getCache();
   // not using a batch
   cache.put("/a", "key", "value"); // will replicate immediately
   // using a batch
   cache.put("/a", "key", "value");
   cache.put("/b", "key", "value");
   cache.put("/c", "key", "value");
   cache.endBatch(true); // This will now replicate the modifications since the batch was started.
   cache.put("/a", "key", "value");
   cache.put("/b", "key", "value");
   cache.put("/c", "key", "value");
   cache.endBatch(false); // This will "discard" changes made in the batch