尝试使用SystemCommandTasklet分割文件 - 系统命令的执行未在超时

时间:2017-04-19 15:27:49

标签: spring-batch

我是新手使用Spring-batch而我正试图获得SystemCommandTasklet函数的句柄。文件不会从代码中分离出来。如果作为unix命令执行,split工作正常

<!-- spring batch core settings -->
<import resource="../config/context.xml" />


<job id="accountingJob" xmlns="http://www.springframework.org/schema/batch">

  <step id="step1" xmlns="http://www.springframework.org/schema/batch">

     <tasklet ref="fileSplittingTasklet" />              

</step>  
</job>

<!-- Jobs to run -->

<bean id="fileSplittingTasklet" class="org.springframework.batch.core.step.tasklet.SystemCommandTasklet" scope="step">
<property name="command" value="split -a 5 -l 4 #{jobParameters['inputFile']} #{jobParameters['stagingDirectory']}"/>
<property name="timeout" value="60000"/>
<property name="workingDirectory" value="/test/temp"/>  

调用代码public class App {

public static void main(String[] args) {

    App obj = new App();
    obj.run();

}

private void run() {

    String[] springConfig = { "spring/batch/jobs/job-partitioner.xml" };

    ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);

    JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
    Job job = (Job) context.getBean("accountingJob");

    try {

        //JobParameters param = new JobParametersBuilder().addString("age", "20").toJobParameters();

        JobExecution execution = jobLauncher.run(job, new JobParameters());

        System.out.println("Exit Status : " + execution.getStatus());

        System.out.println("Exit Status : " + execution.getAllFailureExceptions());

    } catch (Exception e) {
        e.printStackTrace();
    }

    System.out.println("Done");

}

}`

获得超时错误并且没有发生分裂。请从控制台

中找到以下错误
INFO: Executing step: [step1]

2017年4月19日上午7:07:33 org.springframework.batch.core.step.AbstractStep执行 严重:执行步骤时遇到错误 org.springframework.batch.core.step.tasklet.SystemCommandException:系统命令的执行未在超时内完成         在org.springframework.batch.core.step.tasklet.SystemCommandTasklet.execute(SystemCommandTasklet.java:109)         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)         at java.lang.reflect.Method.invoke(Method.java:606)         在org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)         在org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)         在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)         在org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)         在org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)         在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)         在org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)         在com.sun.proxy。$ Proxy2.execute(未知来源)         在org.springframework.batch.core.step.tasklet.TaskletStep $ ChunkTransactionCallback.doInTransaction(TaskletStep.java:395)         在org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:131)         在org.springframework.batch.core.step.tasklet.TaskletStep $ 2.doInChunkContext(TaskletStep.java:267)         在org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:77)         在org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:368)         在org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)         在org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)         在org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:253)         在org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)         在org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:137)         在org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)         在org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)         在org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:152)         在org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:131)         在org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)         在org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:301)         在org.springframework.batch.core.launch.support.SimpleJobLauncher $ 1.run(SimpleJobLauncher.java:134)         在org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)         在org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:127)         在com.mkyong.App.run(App.java:32)         在com.mkyong.App.main(App.java:15)         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)         at java.lang.reflect.Method.invoke(Method.java:606)         在org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)

2017年4月19日上午7:07:33 org.springframework.batch.core.launch.support.SimpleJobLauncher $ 1运行 信息:作业:[FlowJob:[name = accountingJob]]使用以下参数完成:[{}]和以下状态:[FAILED] 工作参数{} 退出状态:失败 Job ParametersexitCode = FAILED; exitDescription = 退出状态:[org.springframework.batch.core.step.tasklet.SystemCommandException:执行系统命令未在超时内完成] 完成

0 个答案:

没有答案