Java Reference
In-Depth Information
Most of the launch-context.xml file should look familiar from other examples. However, let's call
out a couple of beans specifically. The first is stepLocator . This instance of BeanFactoryStepLocator is
used to query the current bean factory for any beans of type Step . For partitioning, Spring Batch uses it
to find the remote step configurations located in remote Spring containers.
The other piece of the launch-context.xml file you need to look at is the configuration of the queues
themselves. This example uses three ActiveMQ JMS queues. Fortunately, the ActiveMQ XSD makes it
easy to configure them. All you need to do is configure the bean id and the physical name for each of the
queues.
The configuration is now complete. Just as in the remote-chunking example, you use two Maven
profiles to construct the two jar files required for this example. First, build using the mvn clean install
-P listener command to create the jar file used by each of the worker JVMs. To build the jar file you use
to execute the job, use the default profile via mvn clean install .
To execute the job, you need to execute three Java processes. The first two serve as the slave nodes
for the job; execute them by running java -jar partitioning-0.0.1-listener-SNAPSHOT.jar using the
jar you created with the -P listener option. With both of those nodes running, you can run the job with
the command java -jar partitioning-0.0.1-SNAPSHOT.jar jobs/geocodeJob.xml geocodingJob . When
the job completes, you can verify the results by looking at the Customers table in the database and
verifying that everyone in the table has longitude and latitude values saved.
Using partitioning as a way to scale a Spring Batch job is a great way to take advantage of the
computing power of multiple servers. This approach is different than remote chunking, but it provides
its own set of benefits for remote processing.
Summary
One of the primary reasons for using Spring Batch is its ability to scale without having a large impact on
your existing code base. Although you could write any of these features yourself, none of them are easy
to implement well, and it doesn't make sense to reinvent the wheel. Spring Batch provides an excellent
set of ways to scale jobs with a number of options.
This chapter looked at how to profile jobs to obtain information about where bottlenecks exist. You then
worked through examples of each of the four options Spring Batch provides for scalability: parallel steps,
multithreaded steps, remote chunking, and partitioning.
 
Search WWH ::




Custom Search