简体   繁体   中英

Spring batch job running multiple times

I have created spring batch jobs and for launching the same we have provided rest client which will pass the job name in the url. Ex.: http://localhost:8080/ProjectName/launcher/jobs/updateFeedsJob This url will launch the updateFeedsJob job. Now the issue is after hitting the url, the same job is running multiple
times(5), one in every minute in unix after deploying the same in tomcat7
while in local it is running fine. Also, the overall job will complete in around 4-5 minutes. I have googled a lot but no proper solution for the same.

Any suggestions.

Code:

Launcher class:

@Path("/launcher")
public class LaunchController {
static String[] springConfig = { "spring/batch/jobs/job-update*.xml" };

@GET
@Path("/semjobs/{jobname}")
@Produces("application/xml")
public Response getScmJobs(@PathParam("jobname") String jobname) {
    {
        JobDetails jobdetails = new JobDetails();
        ApplicationContext context = new ClassPathXmlApplicationContext(springConfig);
    JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
    String category = EMPTY_STRING; 
    jobdetails.setJobname(jobname);
    Job job = (Job) context.getBean(jobname);
    JobExecution executionall = null;
    String inputpath = EMPTY_STRING;
                try {
                    inputpath = loadPropertiesFile(jobname);
                } catch (Exception e) {
                    LOGGER.error("Error occured while loading the properties file -> " + e);
                }
                executionall = jobLauncher.run(job, new JobParametersBuilder().addString("inputFile", inputpath).addDate("date", new Date()).toJobParameters());                
                if (executionall != null) {
        jobdetails.setJobstatus(executionall.getExitStatus().getExitCode());
                    jobdetails.setJobid(executionall.getJobId());
                }   
        } catch (Exception e) {
            LOGGER.error("Error occured while launching the job -> " + e);
        }

        return Response.status(200).entity(jobdetails).build();
    }

Spring batch job is common with flatfileitemreader(reading from csv), processor(updating adwords api feed details, this step takes approx. 40 sec. for each record in the csv file which has around 40 records) and customized writer which is updating the records in the db.

WEB.xml

<web-app>
    <display-name>Archetype Created Web Application</display-name>
    <!-- Auto scan REST service -->
    <context-param>
        <param-name>resteasy.scan</param-name>
        <param-value>true</param-value>
    </context-param>

    <servlet>
        <servlet-name>resteasy-servlet</servlet-name>
        <servlet-class>
            org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
        </servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>resteasy-servlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

well i might have a solution - but it is not the appropriate one .

You can add a job Listerine to your main job which conclude your application

You can call System.Exit(0) - in the after-job method of that listner.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM