@@ -165,6 +165,39 @@ public Long start(String jobName, Properties parameters)
165165
166166 }
167167
168+ /**
169+ * Start a new instance of a job with the specified parameters. If the job defines a
170+ * {@link JobParametersIncrementer}, then the incrementer will be used to calculate
171+ * the next parameters in the sequence and the provided parameters will be ignored.
172+ * @param job the {@link Job} to start
173+ * @param jobParameters the {@link JobParameters} to start the job with
174+ * @return the {@link JobExecution} that was started
175+ * @throws NoSuchJobException if the given {@link Job} is not registered
176+ * @throws JobParametersInvalidException thrown if any of the job parameters are
177+ * @throws JobExecutionAlreadyRunningException if the JobInstance identified by the
178+ * properties already has an execution running. invalid.
179+ * @throws JobRestartException if the execution would be a re-start, but a re-start is
180+ * either not allowed or not needed.
181+ * @throws JobInstanceAlreadyCompleteException if the job has been run before with the
182+ * same parameters and completed successfully
183+ * @throws IllegalArgumentException if the job or job parameters are null.
184+ */
185+ public JobExecution start (Job job , JobParameters jobParameters )
186+ throws NoSuchJobException , JobInstanceAlreadyCompleteException , JobExecutionAlreadyRunningException ,
187+ JobRestartException , JobParametersInvalidException {
188+ Assert .notNull (job , "The Job must not be null." );
189+ Assert .notNull (jobParameters , "The JobParameters must not be null." );
190+ if (job .getJobParametersIncrementer () != null ) {
191+ if (logger .isWarnEnabled ()) {
192+ logger .warn (String .format (
193+ "Attempting to launch the job %s which defines an incrementer with additional parameters={%s}. Those parameters will be ignored." ,
194+ job .getName (), jobParameters ));
195+ }
196+ startNextInstance (job );
197+ }
198+ return run (job , jobParameters );
199+ }
200+
168201 @ SuppressWarnings ("removal" )
169202 @ Override
170203 @ Deprecated (since = "6.0" , forRemoval = true )
@@ -228,8 +261,7 @@ public Long startNextInstance(String jobName)
228261 }
229262
230263 @ Override
231- public JobExecution startNextInstance (Job job )
232- throws NoSuchJobException , UnexpectedJobExecutionException , JobParametersInvalidException {
264+ public JobExecution startNextInstance (Job job ) throws UnexpectedJobExecutionException {
233265 Assert .notNull (job , "Job must not be null" );
234266 Assert .notNull (job .getJobParametersIncrementer (),
235267 "No job parameters incrementer found for job=" + job .getName ());
@@ -271,6 +303,9 @@ public JobExecution startNextInstance(Job job)
271303 String .format (ILLEGAL_STATE_MSG , "job instance already complete" , job .getName (), nextParameters ),
272304 e );
273305 }
306+ catch (JobParametersInvalidException e ) {
307+ throw new UnexpectedJobExecutionException ("Invalid job parameters " + nextParameters , e );
308+ }
274309
275310 }
276311
0 commit comments