Does GridGain support distributed lock?
In my scenario, I want to add distributed lock in my code and make sure only one node executes the code at the same time. Here is the sample code:
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);
Thanks, Bill
Yes, GridGain supports distributed locks, as well as distributed transactions. Please take a look at Basic Distributed Locks documentation in Getting Started guide.