crontab

一般地,很多系统里都会有定时跑批的需求。实现的方式可以是java自带的time和timetask,也可以使用系统的脚本对java进行调度。

使用time,在集群的环境下需要考虑并发,所以需要和主工程分开发布,显得有些麻烦,不过因为都是工程的形式,对于开发者和后期维护者相对较便捷。

另外一种方式就是crontab,也就是下面的代码实现的。即通过系统的调度,实现业务功能,如此这块功能就不用单独维护。当然这个调度只是简单的时间间隔,对于日历形式的,就不如time的形式了

echo
echo "**************"
fNme='ConBatch.sh'
multiFlag=`ps aux|grep $fNme|grep -v grep|awk '{print $2}'`
echo "$multiFlag"
if [ -n "$multiFlag" ]
        then
        echo "*****"
else
        echo "*******"
              #! /bin/sh

                                CLASS_PATH=/home/shell/cash/BATCH.jar
                                LIB_PATH=/home/shell/cash/cashlib

                                CLASS_PATH=$CLASS_PATH:$LIB_PATH/activation-1.1.jar
                                CLASS_PATH=$CLASS_PATH:$LIB_PATH/axis.jar
                                CLASS_PATH=$CLASS_PATH:$LIB_PATH/classes12.jar
                                CLASS_PATH=$CLASS_PATH:$LIB_PATH/commons-collections.jar
                                CLASS_PATH=$CLASS_PATH:$LIB_PATH/log4j-1.2.13.jar
                                CLASS_PATH=$CLASS_PATH:$LIB_PATH/mail.jar
                                CLASS_PATH=$CLASS_PATH:$LIB_PATH/saaj.jar
                                CLASS_PATH=$CLASS_PATH:$LIB_PATH/wsdl4j.jar
                                CLASS_PATH=$CLASS_PATH:$LIB_PATH/servlet-api.jar
                                export CLASS_PATH

/usr/java6_64/bin/java -classpath $CLASS_PATH com.service.cash.ConBatch
fi

你可能感兴趣的:(crontab)