我已经创建了spring batch作业,为了启动它,我们提供了rest客户端,它将在url中传递作业名称。示例:http://localhost:8080/ProjectName/launcher/jobs/updateFeedsJob此url将启动updateFeedsJob作业。现在的问题是,在命中url之后,同一个作业正在运行多个
次数(5),在tomcat7中部署后,在unix中每分钟一个
而在本地它运行得很好。此外,整个工作将在大约4-5分钟内完成。我在谷歌上搜索了很多,但同样没有合适的解决方案。
有什么建议吗。
代码:
启动器类:
@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批处理任务通常用于平板文件项目阅读器(从csv读取)、处理器(更新adwords api提要详细信息),这一步大约需要。40秒对于具有大约40条记录的csv文件中的每条记录)和正在更新数据库中的记录的定制写入器。
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>发布于 2015-05-19 18:35:21
好吧,我可能有一个解决方案--但它不是合适的。
您可以将作业列表添加到结束应用程序的主要作业中
您可以在该listner的任务后方法中调用System.Exit(0) -。
https://stackoverflow.com/questions/30304849
复制相似问题