Dmitriy Setrakyan manages daily operations of GridGain Systems and brings over 12 years of experience to GridGain Systems which spans all areas of application software development from design and architecture to team management and quality assurance. His experience includes architecture and leadership in development of distributed middleware platforms, financial trading systems, CRM applications, and more. Dmitriy is a DZone MVB and is not an employee of DZone and has posted 49 posts at DZone. You can read more from them at their website. View Full User Profile

Cheat Sheet: GridGain vs. GigaSpaces

  • submit to reddit

GridGain - Grid Computing Made SimpleIn his SyncRemoting Cookbook blog, Owen Taylor from GigaSpaces outlines a cheat-sheet that he created for writing GigaSpaces apps. While you can go ahead and read all the required steps from Owen's blog, I just want to counter it with GridGain cheat sheet you would use for creating the same app:

  1. Create GridTask implementation (you need to implement 2 methods, 'map(..) or split(..)' and 'reduce(..)').
  2. Start multiple stand-alone GridGain nodes (if not already started) by executing or gridgain.bat scripts.
  3. Execute the task you created directly from IDE of your choice (Elipse, IDEA, NetBeans, ...) by calling Grid.execute(MyTask.class, ..) method.

This comparison kind of speaks for itself. Note how there are no explicit deployment steps either. With GridGain, all classes are peer-class-loaded automatically.

Below is all the code that you would need to write with GridGain. First we create MyWidgetTask which extends convenience GridTaskSplitAdapter adapter and implements 2 methods, 'split(..)' and 'reduce(..)'.

public class MyWidgetTask extends GridTaskSplitAdapter<Object, Double> {
// Split task into multiple jobs to run on remote nodes.
public Collection<? extends GridJob> split(int gridSize, Object arg) {
List<GridJobAdapter<Object>> jobs =
new ArrayList<GridJobAdapter<Object>>(gridSize);

for (int i = 0; i < gridSize; i++) {
// Create jobs to sent to remote nodes.
jobs.add(new GridJobAdapter<Object>() {
// This code will run on remote grid nodes.
public Serializable execute() {
// Access jboss cache
// (could be any other cache or even local HashMap).
Map<Integer, Widget> widgets = cache.getRoot().

double priceTotal = 0.0d;

// Calculate average price of all widgets
// stored on the grid node this job is
// executing on.
for (Widget widget : widgets.values()) {
priceTotal += widget.getPrice();

return priceTotal / widgets.size();

// Combines all results received from remote nodes.
public Double reduce(List<GridJobResult> results) {
double priceTotal = 0.0d;

for (GridJobResult res : results) {
double price = res.getData();

priceTotal += price;

// Return average widget price.
return priceTotal / results.size();

Now, let's execute our task on the Grid:

public class MyWidgetExample {
public static void main(String[] args) {
Grid grid = GridFactory.start();

try {
GridTaskFuture<Double> future = grid.execute(MyWidgetTask.class, null);

System.out.println("Average widget price is: " + future.get());
finally {

This is it as far as coding. GridGain also does not require any XML configuration unless you want to change the defaults.

Oh yeah... I also forgot to mention that GridGain is Open Source and is absolutely free to use ;-)

Published at DZone with permission of Dmitriy Setrakyan, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)