Language: Java
Performance / In-Memory Data Grid
Hazelcast was developed to enable real-time, scalable, and fault-tolerant data processing across clusters. It supports in-memory computing, distributed caching, and event-driven architectures, making it ideal for microservices, high-throughput applications, and low-latency systems.
Hazelcast is a distributed in-memory data grid and caching platform for Java. It provides high-performance storage for key-value data, distributed maps, queues, topics, and support for distributed computing, clustering, and transactions.
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>5.3.2</version>
</dependency>implementation 'com.hazelcast:hazelcast:5.3.2'Hazelcast provides distributed collections such as maps, sets, queues, lists, and topics. It supports automatic clustering, distributed computation, transactions, and persistence to ensure data reliability. Developers can integrate Hazelcast as a cache, compute grid, or in-memory database.
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.map.IMap;
HazelcastInstance hz = Hazelcast.newHazelcastInstance();
IMap<Integer, String> map = hz.getMap("myMap");
map.put(1, "Hello Hazelcast");
System.out.println(map.get(1));
hz.shutdown();Starts a Hazelcast node, creates a distributed map, stores and retrieves a value, and shuts down the instance.
import com.hazelcast.collection.IQueue;
IQueue<String> queue = hz.getQueue("myQueue");
queue.add("Task1");
System.out.println(queue.poll());Demonstrates using a distributed queue for inter-node task processing.
hz.getExecutorService("exec").submit(() -> System.out.println("Running task across cluster"));Executes a task across cluster nodes using Hazelcast's distributed executor service.
import com.hazelcast.transaction.TransactionContext;
TransactionContext context = hz.newTransactionContext();
context.beginTransaction();
try {
IMap<Integer, String> mapTx = context.getMap("myMap");
mapTx.put(2, "Transactional Value");
context.commitTransaction();
} catch(Exception e) {
context.rollbackTransaction();
}Performs atomic operations on distributed data using transactions.
map.addEntryListener(entryEvent -> System.out.println("Entry updated: " + entryEvent), true);Adds a listener to monitor map entry events across the cluster.
Use appropriate collection types (map, queue, set) based on use case.
Enable backups for high availability and fault tolerance.
Use transactions for critical operations to ensure consistency.
Monitor cluster performance and adjust partitions and backups accordingly.
Leverage Hazelcast management center for monitoring and tuning cluster.