Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: is it possible to access two spring batch jobs from same servlet?

  1. #1

    Default is it possible to access two spring batch jobs from same servlet?

    [is it possible to access two spring batch jobs from single servlet?]

    [i have two jobs 1. file to two files 2. two files to two tables. Both batch jobs are individually working fine but when i call from single servlet then it is trowing run time error. ]
    can you please help on this

    web.xml
    -----------
    [<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/CustomCompositeItemWriterJob.xml,
    /WEB-INF/FilesToTablesJob.xml
    </param-value>
    </context-param>]

    uploadservlet.java
    ---------------------
    [PrintWriter out = response.getWriter();
    JobExecution status1 =null;
    JobExecution status2 =null;
    Date date = new Date();
    ServletContext context = getServletContext();
    WebApplicationContext applicationContext1 = WebApplicationContextUtils.getWebApplicationContex t(context);
    WebApplicationContext applicationContext2 = WebApplicationContextUtils.getWebApplicationContex t(context);
    JobLauncher launcher1 = (JobLauncher ) applicationContext1.getBean("jobLauncher");
    JobLauncher launcher2 = (JobLauncher ) applicationContext2.getBean("jobLauncher");
    Job job1 = (Job ) applicationContext1.getBean("singleInputMultipleOu tputsJob");
    JobParameters jobParameters1= new JobParametersBuilder().addDate("schedule.time", date).toJobParameters();
    try
    {
    status1 = launcher1.run((org.springframework.batch.core.Job) job1,jobParameters1);
    }
    catch(Exception e1)
    {
    out.println(e1);
    }
    response.setContentType("text/html");
    out.print(status1.getExecutionContext());
    out.println(status1.getExitStatus());

    String s="Hello, spring batch!";
    String s1="hp";
    String s2="spring batch! done";

    Job job2 = (Job ) applicationContext2.getBean("filesToTablesJob");
    JobParameters jobParameters2= new JobParametersBuilder().addDate("schedule.time", date).toJobParameters();
    try {
    status2 = launcher2.run((org.springframework.batch.core.Job) job2,jobParameters2);
    } catch(Exception e2)
    {
    out.println(e2);
    }

    out.print(status2.getExecutionContext());
    out.println(status2.getExitStatus());
    out.flush();]
    Last edited by Rams; May 10th, 2011 at 08:52 AM. Reason: format not proper

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    For starters, use [ code][/code ] tags when posting code. Next to that don't post duplicates !!!

    You left out the exception which is probably informative...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3

    Default

    Hi,

    Can i get any solution for this...

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    I suggest start reading my previous post and post the stacktrace!
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5

    Default

    can i have those links......pls

  6. #6

    Default

    Hi Marten,

    can you pls provide that like

    Regards,
    Rams

  7. #7
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    No I cannot.. . Read the post!!!!

    Quote Originally Posted by Marten Deinum
    For starters, use [ code][/code ] tags when posting code. Next to that don't post duplicates !!!

    You left out the exception which is probably informative...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  8. #8

    Default

    Hi Marten,

    Actually i am looking all u r links, but i am not able to get that title proper way. atleast can you please give that title then i find that ....


    [the error i am facing is...]

    ERROR - Parsing error at line: 1 in resource=URL [file:e:/output2.csv], input=[]
    org.springframework.batch.item.file.FlatFileParseE xception: Parsing error at line: 1, input=[]
    at org.springframework.batch.item.file.mapping.Defaul tLineMapper.mapLine(DefaultLineMapper.java:49)
    at org.springframework.batch.item.file.FlatFileItemRe ader.doRead(FlatFileItemReader.java:179)
    at org.springframework.batch.item.support.AbstractIte mCountingItemStreamItemReader.read(AbstractItemCou ntingItemStreamItemReader.java:84)
    at org.springframework.batch.core.step.item.SimpleChu nkProvider.doRead(SimpleChunkProvider.java:90)
    at org.springframework.batch.core.step.item.SimpleChu nkProvider.read(SimpleChunkProvider.java:127)
    at org.springframework.batch.core.step.item.SimpleChu nkProvider$1.doInIteration(SimpleChunkProvider.jav a:106)
    at org.springframework.batch.repeat.support.RepeatTem plate.getNextResult(RepeatTemplate.java:352)
    at org.springframework.batch.repeat.support.RepeatTem plate.executeInternal(RepeatTemplate.java:212)
    at org.springframework.batch.repeat.support.RepeatTem plate.iterate(RepeatTemplate.java:143)
    at org.springframework.batch.core.step.item.SimpleChu nkProvider.provide(SimpleChunkProvider.java:103)
    at org.springframework.batch.core.step.item.ChunkOrie ntedTasklet.execute(ChunkOrientedTasklet.java:64)
    at org.springframework.batch.core.step.tasklet.Taskle tStep$2.doInChunkContext(TaskletStep.java:264)
    at org.springframework.batch.core.scope.context.StepC ontextRepeatCallback.doInIteration(StepContextRepe atCallback.java:67)
    at org.springframework.batch.repeat.support.RepeatTem plate.getNextResult(RepeatTemplate.java:352)
    at org.springframework.batch.repeat.support.RepeatTem plate.executeInternal(RepeatTemplate.java:212)
    at org.springframework.batch.repeat.support.RepeatTem plate.iterate(RepeatTemplate.java:143)
    at org.springframework.batch.core.step.tasklet.Taskle tStep.doExecute(TaskletStep.java:239)
    at org.springframework.batch.core.step.AbstractStep.e xecute(AbstractStep.java:197)
    at org.springframework.batch.core.job.AbstractJob.han dleStep(AbstractJob.java:348)
    at org.springframework.batch.core.job.flow.FlowJob.ac cess$100(FlowJob.java:43)
    at org.springframework.batch.core.job.flow.FlowJob$Jo bFlowExecutor.executeStep(FlowJob.java:137)
    at org.springframework.batch.core.job.flow.support.st ate.StepState.handle(StepState.java:60)
    at org.springframework.batch.core.job.flow.support.Si mpleFlow.resume(SimpleFlow.java:144)
    at org.springframework.batch.core.job.flow.support.Si mpleFlow.start(SimpleFlow.java:124)
    at org.springframework.batch.core.job.flow.FlowJob.do Execute(FlowJob.java:105)
    at org.springframework.batch.core.job.AbstractJob.exe cute(AbstractJob.java:250)
    at org.springframework.batch.core.launch.support.Simp leJobLauncher$1.run(SimpleJobLauncher.java:110)
    at java.lang.Thread.run(Unknown Source)
    Caused by: org.springframework.batch.item.file.transform.Inco rrectTokenCountException: Incorrect number of tokens found in record: expected 7 actual 0
    at org.springframework.batch.item.file.transform.Abst ractLineTokenizer.tokenize(AbstractLineTokenizer.j ava:90)
    at org.springframework.batch.item.file.mapping.Defaul tLineMapper.mapLine(DefaultLineMapper.java:46)
    ... 27 more
    ERROR - Encountered an error executing the step: class org.springframework.batch.item.file.FlatFileParseE xception: Parsing error at line: 1, input=[]
    org.springframework.batch.item.file.FlatFileParseE xception: Parsing error at line: 1, input=[]
    at org.springframework.batch.item.file.mapping.Defaul tLineMapper.mapLine(DefaultLineMapper.java:49)
    at org.springframework.batch.item.file.FlatFileItemRe ader.doRead(FlatFileItemReader.java:179)
    at org.springframework.batch.item.support.AbstractIte mCountingItemStreamItemReader.read(AbstractItemCou ntingItemStreamItemReader.java:84)
    at org.springframework.batch.core.step.item.SimpleChu nkProvider.doRead(SimpleChunkProvider.java:90)
    at org.springframework.batch.core.step.item.SimpleChu nkProvider.read(SimpleChunkProvider.java:127)
    at org.springframework.batch.core.step.item.SimpleChu nkProvider$1.doInIteration(SimpleChunkProvider.jav a:106)
    at org.springframework.batch.repeat.support.RepeatTem plate.getNextResult(RepeatTemplate.java:352)
    at org.springframework.batch.repeat.support.RepeatTem plate.executeInternal(RepeatTemplate.java:212)
    at org.springframework.batch.repeat.support.RepeatTem plate.iterate(RepeatTemplate.java:143)
    at org.springframework.batch.core.step.item.SimpleChu nkProvider.provide(SimpleChunkProvider.java:103)
    at org.springframework.batch.core.step.item.ChunkOrie ntedTasklet.execute(ChunkOrientedTasklet.java:64)
    at org.springframework.batch.core.step.tasklet.Taskle tStep$2.doInChunkContext(TaskletStep.java:264)
    at org.springframework.batch.core.scope.context.StepC ontextRepeatCallback.doInIteration(StepContextRepe atCallback.java:67)
    at org.springframework.batch.repeat.support.RepeatTem plate.getNextResult(RepeatTemplate.java:352)
    at org.springframework.batch.repeat.support.RepeatTem plate.executeInternal(RepeatTemplate.java:212)
    at org.springframework.batch.repeat.support.RepeatTem plate.iterate(RepeatTemplate.java:143)
    at org.springframework.batch.core.step.tasklet.Taskle tStep.doExecute(TaskletStep.java:239)
    at org.springframework.batch.core.step.AbstractStep.e xecute(AbstractStep.java:197)
    at org.springframework.batch.core.job.AbstractJob.han dleStep(AbstractJob.java:348)
    at org.springframework.batch.core.job.flow.FlowJob.ac cess$100(FlowJob.java:43)
    at org.springframework.batch.core.job.flow.FlowJob$Jo bFlowExecutor.executeStep(FlowJob.java:137)
    at org.springframework.batch.core.job.flow.support.st ate.StepState.handle(StepState.java:60)
    at org.springframework.batch.core.job.flow.support.Si mpleFlow.resume(SimpleFlow.java:144)
    at org.springframework.batch.core.job.flow.support.Si mpleFlow.start(SimpleFlow.java:124)
    at org.springframework.batch.core.job.flow.FlowJob.do Execute(FlowJob.java:105)
    at org.springframework.batch.core.job.AbstractJob.exe cute(AbstractJob.java:250)
    at org.springframework.batch.core.launch.support.Simp leJobLauncher$1.run(SimpleJobLauncher.java:110)
    at java.lang.Thread.run(Unknown Source)
    Caused by: org.springframework.batch.item.file.transform.Inco rrectTokenCountException: Incorrect number of tokens found in record: expected 7 actual 0
    at org.springframework.batch.item.file.transform.Abst ractLineTokenizer.tokenize(AbstractLineTokenizer.j ava:90)
    at org.springframework.batch.item.file.mapping.Defaul tLineMapper.mapLine(DefaultLineMapper.java:46)
    ... 27 more

  9. #9
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    Again use [ code][/code ] tags when posting code/xml/stacktraces so that it remains readable!

    I also suggest reading the stacktrace as that clearly states there is nothing to read (input is empty), my guess is your JobParameters for the second job are wrong.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  10. #10

    Default

    Individually those two jobs are running succefully. But when i call from the single servlet then it is creating problem.

    i guess there is some problem in web.xml or in uploadservlet.java

    can u pls correct me...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •