Java分布式記憶體開源實現:Hazelcast

來源:互聯網
上載者:User

Hazelcast是一個Java的開源分布式記憶體實現,它具有以下特性:

01    Distributed implementations of java.util.{Queue, Set, List, Map}
02    Distributed implementation of java.util.concurrent.ExecutorService
03    Distributed implementation of java.util.concurrency.locks.Lock
04    Distributed Topic for publish/subscribe messaging
05    Transaction support and J2EE container integration via JCA
06    Distributed listeners and events
07    Support for cluster info and membership events
08    Dynamic HTTP session clustering
09    Dynamic clustering
10    Dynamic scaling to hundreds of servers
11    Dynamic partitioning with backups
12    Dynamic fail-over
13    Super simple to use; include a single jar
14    Super fast; thousands of operations per sec.
15    Super small; less than a MB
16    Super efficient; very nice to CPU and RAM

安裝也非常方便:

1    Download hazelcast-version.zip from www.hazelcast.com
2    Unzip hazelcast-version.zip file
3    Add hazelcast.jar file into your classpath

要使用分布式的Map,只需要以下代碼即可實現:

 

import com.hazelcast.core.Hazelcast;import java.util.Map;import java.util.Collection;Map<String, Customer> 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"));Collection<Customer> colCustomers = mapCustomers.values();for (Customer customer : colCustomers) {// process customer}

 

Hazelcast的官網上面有一個非常直觀的視頻:http://www.hazelcast.com/screencast.jsp,建議有興趣的朋友花10分鐘時間看看。

還有一份PDF可以參考:http://roma.javaday.it/javaday2010/sites/default/files/ClusteringHazelcast-javaday.pdf。

Hazelcast作為一款與ZooKeeper類似的開源實現,我在網上找了一篇相關的文章:http://blog.armstrongconsulting.com/?p=132
在這篇文章中有一段這樣寫道:

I had occasional hangs with Hazelcast 1.8.4 which caused me to switch to Zookeeper. As expected, Zookeeper was a lot harder to use than Hazelcast – you need Zookeeper installed on 3 servers. There’s no official java client, just some recipes and I found an implementation of Zookeeper locks called Cages on google code. For a java developer, Hazelcast is obviously way easier to use.

另外,在Hazelcast的官方文檔中,提到了Hazelcast的叢集機制:

If there is no existing node, then the node will be the first member of the cluster. If multicast is enabled then it will start a multicast listener so that it can respond to incoming join requests. Otherwise it will listen for join request coming via TCP/IP.

If there is an existing cluster already, then the oldest member in the cluster will receive the join request and check if the request is for the right group. If so, the oldest member in the cluster will start the join process.

In the join process, the oldest member will:

  • send the new member list to all members

  • tell members to sync data in order to balance the data load

Every member in the cluster has the same member list in the same order. First member is the oldest member so if the oldest member dies, second member in the list becomes the first member in the list and the new oldest member.

從這點可以看出,雖然Hazelcast沒有所謂的“Master”,但是仍然有一個Leader節點(the oldest member),這個概念與ZooKeeper中的Leader類似,但是實現原理卻完全不同。同時,Hazelcast中的資料是分布式的,每一個member持有部分資料和相應的backup資料,這點也與ZooKeeper不同。

雖然Hazelcast應用便捷,但是要將其實際應用於生產環境,還是具有一定的風險的,這個需要大量的實際應用來驗證。

 

更多關於ZooKeeper的文章請參考:http://www.cnblogs.com/gpcuster/tag/ZooKeeper/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.