Hazelcast 参考文档-3
?
2.?分布式数据结构以下是你如何获取现有的数据结构的实例(map, queue, set, lock,topic, 等),以及当一个实例被创建或销毁时,你如何可以监听到实例的事件通知。
??????}
}
2.1.?分布式Queue?
Hazelcast分布式队列是一个java.util.concurrent.BlockingQueue的实现.
import com.hazelcast.core.Hazelcast;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
?
BlockingQueue<MyTask> q =Hazelcast.getQueue("tasks");
q.put(new MyTask());
MyTask task = q.take();
?
boolean offered = q.offer(new MyTask(), 10, TimeUnit.SECONDS);
task = q.poll (5, TimeUnit.SECONDS);
if (task != null) {
??????? //process task
}
?
如果你有1亿个 “任务”任务排队,你正在超过10个JVM(或服务器)上运行相应代码,然后每个服务器进行1千万任务对象(加上备份)。在集群范围内应用先进先出(FIFO)顺序处理所有队列操作。队列中的用户对象(如上面的例子的MyTask)必须是可序列化的(Serializable)。每JVM为队列提供的最大容量和TTL(生存时间)是可配置的,如显示在下面的例子。
<hazelcast>
??????? ...
??????? <queuename="default">
??????? <!--
??????????? Maximum size ofthe queue. When a JVM's local queue size reaches the maximum,
??????????? all put/offeroperations will get blocked until the queue size
??????????? of the JVM goesdown below the maximum.
??????????? Any integerbetween 0 and Integer.MAX_VALUE. 0 means Integer.MAX_VALUE. Default is 0.
??????? -->
???????<max-size-per-jvm>10000</max-size-per-jvm>
???????
??????? <!--
??????????? Maximum number ofseconds for each item to stay in the queue. Items that are
??????????? not consumed in<time-to-live-seconds> will get automatically evicted from the queue.
??????????? Any integerbetween 0 and Integer.MAX_VALUE. 0 means infinite. Default is 0.
??????? -->
???????<time-to-live-seconds>0</time-to-live-seconds>
??? </queue>
</hazelcast>
?