GridGain是否支持分布式锁定?
在我的场景中,我想在我的代码中添加分布式锁,并确保只有一个节点同时执行代码。以下是示例代码:
final Grid grid = GridGain.start("config/default-config.xml");
GridCache<Object, Object> cache = grid.cache("partitioned_tx");
ExecutorService exec = grid.compute().executorService();
//Lock here
for(int i=0;i<100;i++){
final int index = i;
exec.submit(new GridRunnable() {
private static final long serialVersionUID = -8705359518901621360L;
@Override
public void run() {
System.out.println("The task-"+index+" is executed on "+grid.forLocal().node().toString());
}
});
}
//unlock here
exec.shutdown();
exec.awaitTermination(0, TimeUnit.MILLISECONDS);
谢谢, 比尔