Over a million developers have joined DZone.

Cheat Sheet: GridGain vs. GigaSpaces

DZone's Guide to

Cheat Sheet: GridGain vs. GigaSpaces

· Java Zone ·
Free Resource

Build vs Buy a Data Quality Solution: Which is Best for You? Gain insights on a hybrid approach. Download white paper now!

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 gridgain.sh 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 ;-)

Build vs Buy a Data Quality Solution: Which is Best for You? Maintaining high quality data is essential for operational efficiency, meaningful analytics and good long-term customer relationships. But, when dealing with multiple sources of data, data quality becomes complex, so you need to know when you should build a custom data quality tools effort over canned solutions. Download our whitepaper for more insights into a hybrid approach.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}