public CompletableFuture < Void > submit ( JobExecution jobExecution , ExecutorService executorService ) { overwriteJobExecutionUser ( jobExecution ) ; Job molgenisJob = saveExecutionAndCreateJob ( jobExecution ) ; Progress progress = jobExecutionRegistry . registerJobExecution ( jobExecution ) ; CompletableFuture < Void > completableFuture = CompletableFuture . runAsync ( ( ) -> runJob ( jobExecution , molgenisJob , progress ) , executorService ) ; return completableFuture . handle ( ( voidResult , throwable ) -> { if ( throwable != null ) { handleJobException ( jobExecution , throwable ) ; } jobExecutionRegistry . unregisterJobExecution ( jobExecution ) ; return voidResult ; } ) ; }
Saves execution in the current thread then creates a Job and submits that for asynchronous execution to a specific ExecutorService .