Over a million developers have joined DZone.

Hazelcast 1.0: Distributed Queue, Set, Map, and Lock

Hazelcast, clustering and highly scalable data distribution platform for Java, is now ready to rock and roll!

  • Distributed implementations of java.util.{Queue, Set, List, Map}
  • Distributed locks via java.util.concurrency.locks.Lock
  • Support for cluster info and membership events
  • Dynamic discovery
  • Dynamic scaling to hundreds of servers
  • Dynamic partitioning with backups
  • Dynamic fail-over

  • Super simple to use; include a single jar.
  • Super fast; thousands of operations per sec.
  • Super small; less than a MB.
  • Super efficient; very nice to CPU and RAM.

Where to use it:
  • share data/state among many servers
  • cache your data (distributed cache)
  • cluster your application
  • partition your in-memory data
  • distribute workload onto many servers
  • provide fail-safe data management

Code Samples:

 //distributed queue sample..
java.util.Queue q = Hazelcast.getQueue("tasks");
Object myobj = q.poll();

//distributed hash map sample
java.util.Map mapCustomers = Hazelcast.getMap("customers");
mapCustomers.put("1", new Customer("Joe", "Smith"));
mapCustomers.put("2", new Customer("Ali", "Selam"));
mapCustomers.put("3", new Customer("Avi", "Noyan"));

Iterator itValues = mapCustomers.values().iterator();
while (itValues.hasNext()){
Customer customer = (Customer) itValues.next();

//distributed hash set sample
java.util.Set set = Hazelcast.getSet("IBM-Quote-History");
set.add(new Price(10, time1));
set.add(new Price(11, time2));
set.add(new Price(12, time3));
set.add(new Price(11, time4));
Iterator it = set.iterator();
while (it.hasNext()) {
Price price = (Price) it.next();

//distributed locks
java.util.concurrent.locks.Lock lock = Hazelcast.getLock (new MyObject());
lock.lock ();
try {
// do some stuff here..
} finally {

if (lock.tryLock (5000, TimeUnit.MILLISECONDS)) {
try {
// do some stuff here..
} finally {

//cluster interface sample
Cluster cluster = Hazelcast.getCluster();
cluster.addMembershipListener(new MembershipListener(){
public void memberAdded(MembershipEvent membershipEvent) {
System.out.println("MemberAdded " + membershipEvent);

public void memberRemoved(MembershipEvent membershipEvent) {
System.out.println("MemberRemoved " + membershipEvent);



Blog: http://jroller.com/talipozturk

Website: http://www.hazelcast.com


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}