Announcement Announcement Module
Collapse
No announcement yet.
is it possible to access two spring batch jobs from same servlet? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 09:52 AM. Reason: format not proper

  • #2
    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...

    Comment


    • #3
      Hi,

      Can i get any solution for this...

      Comment


      • #4
        I suggest start reading my previous post and post the stacktrace!

        Comment


        • #5
          can i have those links......pls

          Comment


          • #6
            Hi Marten,

            can you pls provide that like

            Regards,
            Rams

            Comment


            • #7
              No I cannot.. . Read the post!!!!

              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...

              Comment


              • #8
                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

                Comment


                • #9
                  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.

                  Comment


                  • #10
                    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...

                    Comment


                    • #11
                      I give up... You really don't want to understand me and ignore my posts.... The stacktrace is quite clear IMHO... Next to that you expect us with just some code, no configuration, no stacktrace to solve your problem... That isn't going to work... I suggest check your configuration there is probably some bean overriding going on, next to that I still suspect that the way you launch your job is faulty.

                      Comment

                      Working...
                      X