@ Override public void scheduleWork ( Work work , long startTimeout , ExecutionContext execContext , WorkListener workListener ) throws WorkException { try { beforeRunCheck ( work , workListener , startTimeout ) ; WorkProxy workProxy = new WorkProxy ( work , startTimeout , execContext , workListener , bootstrapContext , runningWork , true ) ; FutureTask < Void > futureTask = new FutureTask < Void > ( workProxy ) ; bootstrapContext . execSvc . executeGlobal ( futureTask ) ; if ( futures . add ( futureTask ) && futures . size ( ) % FUTURE_PURGE_INTERVAL == 0 ) purgeFutures ( ) ; } catch ( WorkException ex ) { throw ex ; } catch ( Throwable t ) { WorkRejectedException wrex = new WorkRejectedException ( t ) ; wrex . setErrorCode ( WorkException . INTERNAL ) ; if ( workListener != null ) workListener . workRejected ( new WorkEvent ( work , WorkEvent . WORK_REJECTED , work , wrex ) ) ; throw wrex ; } }
This method puts the work on a queue that is later processed by the scheduler thread . This allows the method to return to the caller without having to wait for the thread to start .