2.3.3. Use the Batching API
After the cache is configured to use batching, call
startBatch()
and endBatch()
on the cache as follows to use batching:
Cache cache = cacheManager.getCache();
Example 2.1. Without Using Batch
cache.put("key", "value");
When the
cache.put(key, value);
line executes, the values are replaced immediately.
Example 2.2. Using Batch
cache.startBatch(); cache.put("k1", "value"); cache.put("k2", "value"); cache.put("k3", "value"); cache.endBatch(true); cache.startBatch(); cache.put("k1", "value"); cache.put("k2", "value"); cache.put("k3", "value"); cache.endBatch(false);
When the line
cache.endBatch(true
);
executes, all modifications made since the batch started are replicated.
When the line
cache.endBatch(false
);
executes, changes made in the batch are discarded.