@ Override public Optional < String > trySchedule ( final Tasklet tasklet ) { for ( int i = 0 ; i < idList . size ( ) ; i ++ ) { final int index = ( nextIndex + i ) % idList . size ( ) ; final String workerId = idList . get ( index ) ; if ( idLoadMap . get ( workerId ) < workerCapacity ) { nextIndex = ( index + 1 ) % idList . size ( ) ; return Optional . of ( workerId ) ; } } return Optional . empty ( ) ; }
Checking from nextIndex choose the first worker that fits to schedule the tasklet onto .