Batch Jobs

Structure of a Java Batch Job

Build a standard Java app (not a web app / servlet) into a .jar file

The batch job (java app) will be called by a unix shell script (see below)

The directory structure of the batch job should follow this standard:

./<appname>/
./<appname>/control
./<appname>/control/db
./<appname>/control/lib
./<appname>/msgs
./<appname>/extracts

Put all .jars into the "lib" folder

datasources.xml and dbproperties.xml files go into the "db" folder

Example shell script to setup Java environment and call app

#!/bin/sh

# establish environment
. /etc/server_env.sh
echo $JLINK_BATCH_ENVIRONMENT
echo $ACT_SERVER_ENV

# remove files older than 7 days
find /ifis/db2/financiallink/cams/msgs -mtime +7 -exec rm -f {} \;

# define directory structure
BATCH_HOME=/ifis/db2/financial/cams
LIB_DIR=$BATCH_HOME/control/lib
CONFIG_DIR=$BATCH_HOME/control/db
LOGS_DIR=$BATCH_HOME/msgs
EXTRACTS_DIR=$BATCH_HOME/extracts

# setup java classpath
CLASSPATH=
for jarfile in $LIB_DIR/*.jar
do
   CLASSPATH=$CLASSPATH$jarfile:
done
CLASSPATH=$CLASSPATH$BATCH_HOME/control/db
echo $CLASSPATH

# call job
/usr/java1.6/bin/java \
 -cp $CLASSPATH \
 -Dbatch.env=$ACT_SERVER_ENV \
 -Dconfig.dir=$CONFIG_DIR \
 -Dlogback.configurationFile=$CONFIG_DIR/logback.xml \
 -Dlogging.dir=$LOGS_DIR \
 -Dextracts.dir=$EXTRACTS_DIR \
 -Djlink.app.context.path=$ASHOME \
 -Djlink.datasources.path=$ASHOME/db/ \
 -Djlink.batch=true \
 -Djlink.env=$JLINK_BATCH_ENVIRONMENT \
 -Djlink.batch.batchPath=$ASHOME \
 -Djlink.log.common=true \
 -Djlink.log.exceptions=true \
 -Djlink.log.sql=true \
edu.ucsd.act.cams.Batch2 $1 $2

exit $?

Java App Code

public static void main(String[] args) {
    // standard Java environment method
    batchEnvironment = System.getProperty("batch.env");
    // JLink method
    JLinkJndi.setEnv(System.getProperty( "jlink.env" )); 
    System.out.println(JLinkJndi.getEnv());

    // TODO ...
if (JLinkJndi.isEnvProd())
{
}
else
{
}

Sample Batch Job

Example job using JDBC (no JPA, no Jlink)

Batch Deployment

The ACT Batch job deployment process has been standardized across ACT.

Batch Processing