Java Reference
In-Depth Information
public static void main(String[] args) throws Throwable {
ApplicationContext applicationContext = new
ClassPathXmlApplicationContext("gridservice.xml");
SalutationService salutationServiceImpl = (SalutationService)
applicationContext.getBean("salutationService");
String[] names =("Alan,Arin,Clark,Craig,Drew,Duncan,Gary,Gordon,Fumiko,"+
"Hicham,James,Jordon,Kathy,Ken,Makani,Manuel,Mario, "+
"Mark,Mia,Mike,Nick,Richard,Richelle, "+
"Rod,Ron,Scott,Shaun,Srinivas,Valerie,Venkatesh").split(",");
Locale[] locales = new Locale[]{
Locale.FRENCH, Locale.ENGLISH, Locale.ITALIAN};
for (String name : names) {
System.out.println("Result: " +
salutationServiceImpl.saluteSomeoneInForeignLanguage(name));
}
}
}
When you run this, you'll witness — on as many command-line consoles as you've opened by
clicking on the startup script — the jobs being handled in a round-robin fashion, each on its own node.
If you had 100 names and 10 nodes, you'd notice that each node gets about 10 names listed on the
command line, for example.
10-5. Parallelizing Processing
Problem
You want to build a parallelized solution for a problem that's intrinsically better-suited to parallelization
or that, for want of resources, needs to be chunked.
Solution
Use Map/Reduce to approach the problem concurrently. As was mentioned earlier, decisions to
parallelize shouldn't be taken lightly, but with an eye on the ultimate performance expectations and
tradeoffs.
Approach
Underneath the hood, GridGain works with a GridTask , which tells GridGain how to handle the main
unit of work, GridJob . Sometimes, GridTask splits up and reconciles large jobs. This process is simplified
by abstract adapter classes. In this case, we'll use one called GridifyTaskSplitAdapter , which abstracts
away most of the minutiae of building a map/reduce-oriented solution. It provides two template
methods that we need to override.
 
Search WWH ::




Custom Search