public Future < ? > scheduleJobImmediately ( Properties jobProps , JobListener jobListener , JobLauncher jobLauncher ) { Callable < Void > callable = new Callable < Void > ( ) { @ Override public Void call ( ) throws JobException { try { runJob ( jobProps , jobListener , jobLauncher ) ; } catch ( JobException je ) { LOG . error ( "Failed to run job " + jobProps . getProperty ( ConfigurationKeys . JOB_NAME_KEY ) , je ) ; throw je ; } return null ; } } ; final Future < ? > future = this . jobExecutor . submit ( callable ) ; return new Future ( ) { @ Override public boolean cancel ( boolean mayInterruptIfRunning ) { if ( ! cancelRequested ) { return false ; } boolean result = true ; try { jobLauncher . cancelJob ( jobListener ) ; } catch ( JobException e ) { LOG . error ( "Failed to cancel job " + jobProps . getProperty ( ConfigurationKeys . JOB_NAME_KEY ) , e ) ; result = false ; } if ( mayInterruptIfRunning ) { result &= future . cancel ( true ) ; } return result ; } @ Override public boolean isCancelled ( ) { return future . isCancelled ( ) ; } @ Override public boolean isDone ( ) { return future . isDone ( ) ; } @ Override public Object get ( ) throws InterruptedException , ExecutionException { return future . get ( ) ; } @ Override public Object get ( long timeout , TimeUnit unit ) throws InterruptedException , ExecutionException , TimeoutException { return future . get ( timeout , unit ) ; } } ; }
Schedule a job immediately .