Skip to content

Instantly share code, notes, and snippets.

@rofr
Created September 18, 2014 15:06
Show Gist options
  • Save rofr/b4da21d0a793eba4a850 to your computer and use it in GitHub Desktop.
Save rofr/b4da21d0a793eba4a850 to your computer and use it in GitHub Desktop.
Getting started example code from the gridgain docs
try (Grid g = GridGain.start()) {
Collection<GridCallable<Integer>> calls = new ArrayList<>();
// Iterate through all the words in the sentence and create Callable jobs.
for (final String word : "Count characters using callable".split(" ")) {
calls.add(new GridCallable<Integer>() {
@Override public Integer call() throws Exception {
return word.length();
}
});
}
// Execute collection of Callables on the grid.
Collection<Integer> res = g.compute().call(calls).get();
int sum = 0;
// Add up individual word lengths received from remote nodes.
for (int len : res)
sum += len;
System.out.println(">>> Total number of characters in the phrase is '" + sum + "'.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment