private void scheduleWithDelay ( long delay ) { synchronized ( mutex ) { if ( scheduled && delay < scheduledDelay ) { if ( isPendingFutureReadyOrInProcessing ( ) ) { // Ignore as there is one batch currently in processing or ready to be processed: Log . v ( Log . TAG_BATCHER , "%s: scheduleWithDelay: %d ms, ignored as current batch " + "is ready or in process" , this , delay ) ; return ; } unschedule ( ) ; } if ( ! scheduled ) { scheduled = true ; scheduledDelay = delay ; Log . v ( Log . TAG_BATCHER , "%s: scheduleWithDelay %d ms, scheduled ..." , this , delay ) ; synchronized ( workExecutor ) { if ( ! workExecutor . isShutdown ( ) ) { pendingFuture = workExecutor . schedule ( new Runnable ( ) { @ Override public void run ( ) { Log . v ( Log . TAG_BATCHER , "%s: call processNow ..." , this ) ; processNow ( ) ; Log . v ( Log . TAG_BATCHER , "%s: call processNow done" , this ) ; } } , scheduledDelay , TimeUnit . MILLISECONDS ) ; } } } else Log . v ( Log . TAG_BATCHER , "%s: scheduleWithDelay %d ms, ignored" , this , delay ) ; } }
Schedule the batch processing with the delay . If there is one batch currently in processing the schedule will be ignored as after the processing is done the next batch will be rescheduled .