- //Test.java
- import java.io.IOException;
- public class Test {
- /**
- * @param args
- */
- public static void main(String[] args) {
- try {
- Runtime.getRuntime().exec("sh /fxmweb/test/start.sh");
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
-
//start.sh
- ///fxmweb/good/ 删除改目录下三天前的文件
- find /fxmweb/domains/tstDomain/cgServer -type f ! -ctime -3 -exec rm -f {} /;
以下是xml配置 spring 中设置定时任务
-
- <bean id="forceClearService"
- class="nl.base.service.impl.ForceClearServiceImpl">
- <property name="systemCommands">
- <list>
- <value>
- sh /mts/properties/start.sh
- </value>
- </list>
- </property>
- </bean>
- <bean id="forceClearTrigger"
- class="org.springframework.scheduling.quartz.CronTriggerBean">
- <property name="jobDetail">
- <ref bean="forceClearJob" />
- </property>
- <property name="cronExpression">
- <value>0 * * * * ?</value>
- </property>
- </bean>
- <bean id="scheduler"
- class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
- <property name="triggers">
- <list>
- <ref local="forceClearTrigger" />
- </list>
- </property>
- </bean>
- <bean id="forceClearJob"
- class="org.springframework.scheduling.quartz.JobDetailBean">
- <property name="jobClass">
- <value>nl.base.service.impl.Force</value>
- </property>
- <property name="jobDataAsMap">
- <map>
- <entry key="forceClear">
- <ref bean="forceClearService" />
- </entry>
- </map>
- </property>
- </bean>
-
-
//Force.java
- import org.quartz.JobExecutionContext;
- import org.quartz.JobExecutionException;
- import org.springframework.scheduling.quartz.QuartzJobBean;
- /**
- * 执行系统命令任务类
- * @author cyhgo
- * @since 2008-9-16
- */
- public class Force extends QuartzJobBean {
- private ForceClearServiceImpl forceClear;
- protected void executeInternal(JobExecutionContext context) throws JobExecutionException
- {
- forceClear.executeComm();
- }
- public ForceClearServiceImpl getForceClear() {
- return forceClear;
- }
- public void setForceClear(ForceClearServiceImpl forceClear) {
- this.forceClear = forceClear;
- }
- }
- //ForceClearServiceImpl .java
- import java.io.IOException;
- import java.util.Iterator;
- import java.util.List;
- /**
- * 执行系统命令任务类
- * @author cyhgo
- * @since 2008-9-16
- */
- public class ForceClearServiceImpl{
- /**
- * 系统命令集
- * 清除三天前的所有强平信息
- */
- private List systemCommands;
- public void executeComm()
- {
- if(systemCommands==null) System.out.println("---------");
- for (Iterator it = systemCommands.iterator(); it.hasNext();) {
- String cmd = (String) it.next();
- System.out.println(cmd);
- try {
- Runtime.getRuntime().exec(cmd);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- public List getSystemCommands() {
- return systemCommands;
- }
- public void setSystemCommands(List systemCommands) {
- this.systemCommands = systemCommands;
- }
- }