Develop a simple compute-intensive application
We can write a simple compute-intensive application using a compute-intensive job controller, the command line, or the Apache ANT tool.
- Create a compute-intensive job using a compute-intensive job controller.
- Create a compute-intensive job step.
- Create a Java class that implements the com.ibm.websphere.ci.CIWork interface.
- Implement business logic.
- Optional: For batch applications, provide a job listener.
Provide an implementation for the com.ibm.websphere.batch.listener.JobListener interface to add additional initialization and clean up for jobs and steps. Specify the job listener in the xJCL using the job-level listener element.
The job listener beforeJob() method is invoked before any user artifact is invoked. The job listener afterJob() method is invoked after the last user artifact is invoked. The job listener beforeStep() method is invoked before any step-related user artifact. The job listener afterStep() method is invoked as the last step-related user artifact. Each time the job listener is invoked, it logs a message to the job log.
- Optional: For batch applications, obtain the job step context.
JobStepContext ctx= JobStepContextMgr.getContext();
The JobStepContextMgr service class enables the batch job step to obtain a reference to its JobStepContext object. The job step context provides the following capabilities:
- Access to information that uniquely identifies the context in which the current batch job step runs, for example, the job ID
- A user data area where application-specific information can be passed among the batch programming framework methods during the life of the batch job step
- A transient user data area where application-specific information can be passed across steps
- A persistent user data area where application-specific information is stored across checkpoint/restart
We can use the PersistentMap helper class to simplify the storing of basic types such as boolean and double in the persistent user data area of the job step context.
- Declare a compute-intensive job controller.
- Add a stateless session bean to the deployment descriptor and point to the implementation class that the product provides.
Do so by specifying com.ibm.ws.ci.CIControllerBean as the bean class. Do this specification only once per compute-intensive application.
- Use com.ibm.ws.ci.CIControllerHome for the remote home interface class and com.ibm.ws.ci.CIController for the remote interface class.
- Configure the EJB deployment descriptor.
- Configure a resource reference on the controller bean to the WorkManager wm/CIWorkManager default of the type commonj.work.WorkManager.
- Create compute-intensive jobs using the command line.
- Create a compute-intensive job step.
- Create a Java class that implements the com.ibm.websphere.ci.CIWork interface.
- Implement business logic.
- Optional: For batch applications, obtain the job step context.
JobStepContext ctx= JobStepContextMgr.getContext();
The JobStepContextMgr service class enables the batch job step to obtain a reference to its JobStepContext object. The job step context provides the following capabilities:
- Access to information that uniquely identifies the context in which the current batch job step runs, for example, the job ID
- A user data area where application-specific information can be passed among the batch programming framework methods during the life of the batch job step
- A transient user data area where application-specific information can be passed across steps
- A persistent user data area where application-specific information is stored across checkpoint/restart
We can use the PersistentMap helper class to simplify the storing of basic types such as boolean and double in the persistent user data area of the job step context.
- Open a command prompt and ensure that the directory where the Java executable program is located is included in our PATH variable so that we can run the Java command.
- Issue a Java command.
java -jar pgcbatchpackager.jar -appname=<application name> -jarfile=<jarfile containing POJO step classes> -earfile=<name of the output ear file without .ear> [-utilityjars=<semicolon separated list of utility jars>] [-debug] [-gridjob]For example for batch jobs, issue the command:
java -jar pgcbatchpackager.jar -appname=SimpleCI -jarfile=SimpleCIEJBs.jar -earfile=SimpleCI -gridjob=true
- Create compute-intensive jobs using ANT.
- Create the compute-intensive job step.
- Create a Java class that implements the com.ibm.websphere.ci.CIWork interface.
- Implement business logic.
- Optional: For batch applications, obtain the job step context.
JobStepContext ctx= JobStepContextMgr.getContext();
The JobStepContextMgr service class enables the batch job step to obtain a reference to its JobStepContext object. The job step context provides the following capabilities:
- Access to information that uniquely identifies the context in which the current batch job step runs, for example, the job ID
- A user data area where application-specific information can be passed among the batch programming framework methods during the life of the batch job step
- A transient user data area where application-specific information can be passed across steps
- A persistent user data area where application-specific information is stored across checkpoint/restart
We can use the PersistentMap helper class to simplify the storing of basic types such as boolean and double in the persistent user data area of the job step context.
- For a compute-intensive job, ensure that pgcbatchpackager.jar is on the class path.
- Declare the task.
Use the following command to declare the task:
<taskdef name="pgcpackager" classname="com.ibm.ws.batch.packager.PGCPackager" classpath="${FEBaseDir}/grid.pgc.packager/build/lib/pgcbatchpackager.jar" />
- After compiling the Java files in the application, invoke the pgcpackager task.
<pgcpackager appname="<appname>" earFile="<location name of EAR file to generate>" jarfile="location of the POJO jar file" gridJob="true"/>
Results
You have developed a simple compute-intensive application using a compute-intensive job controller, the command line, or ANT.
What to do next
Install the compute-intensive application and configure WebSphere grid endpoints.
Subtopics
- Compute-intensive programming model
Compute-intensive applications are applications that perform computationally intensive work that does not fit comfortably into the traditional Java EE request and response paradigm.
Related concepts
xJCL elements
Related tasks
Configure WebSphere grid endpoints Deploy batch applications