Announcement Announcement Module
Collapse
No announcement yet.
Executing jobs in Web container using spring-batch-admin Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Executing jobs in Web container using spring-batch-admin

    Hi,
    I am new to spring as a whole, specifically for the spring web framework.
    I have a requirement to run my jobs in a web container, and to complicate the matter, I need to develop it such that the job starts at the start up of the application server and thereafter each URL request results in execution of a step (instead of a job).
    Is there any standard solution to this use case?
    Anyways, I am trying to hack the JobController such that it executes a step instead of executing a job. For this, I need to keep the jobExecution in the servlet context so that I can use same context for every requested step.

    1. Does this sound too weird? Or is there any better way to do it?

    2. How can I access servletContext in my job? This is my Tasklet

    Code:
    @Override
    	public RepeatStatus execute(StepContribution cont, ChunkContext context) throws Exception {
    		List<FileSystemResource> files = filesProvider.getFiles();
    		//Put the list in servlet Context here......
    		}
    		return RepeatStatus.FINISHED;
    	}
    Last edited by husbas; Mar 18th, 2011, 10:21 AM.

  • #2
    I tried using jobExecutionContext to put some data in so that I can use it in between step execution.
    Code:
    chunkContext.getStepContext().getJobExecutionContext().put(file.getFilename(), file);
    But I got the following exception:

    Code:
    java.lang.UnsupportedOperationException
    	at java.util.Collections$UnmodifiableMap.put(Collections.java:1285)
    	at com.risk.riskstat.loader.SessionStarter.execute(SessionStarter.java:26)
    Is there a way of passing objects among steps in a job?

    Comment


    • #3
      Is there a way of passing objects among steps in a job?
      just use some holder Spring bean: it's empty at the beginning, it's injected into two steps (reader/writer, tasklet), one step fills it in with some value and the other step reads from the holder.

      Comment

      Working...
      X