private static Future<?> directExecute(Runnable runnable,int delay){
  Future<?> future=null;
  if (delay > 0) {
    if (!(executor instanceof ScheduledExecutorService)) {
      throw new IllegalArgumentException("The executor set does not support scheduling");
    }
    ScheduledExecutorService scheduledExecutorService=(ScheduledExecutorService)executor;
    future=scheduledExecutorService.schedule(runnable,delay,TimeUnit.MILLISECONDS);
  }
 else {
    if (executor instanceof ExecutorService) {
      ExecutorService executorService=(ExecutorService)executor;
      future=executorService.submit(runnable);
    }
 else {
      executor.execute(runnable);
    }
  }
  return future;
}

private static Future < ? > directExecute ( Runnable runnable , int delay ) { Future < ? > future = null ; if ( delay > 0 ) { if ( ! ( executor instanceof ScheduledExecutorService ) ) { throw new IllegalArgumentException ( "The executor set does not support scheduling" ) ; } ScheduledExecutorService scheduledExecutorService = ( ScheduledExecutorService ) executor ; future = scheduledExecutorService . schedule ( runnable , delay , TimeUnit . MILLISECONDS ) ; } else { if ( executor instanceof ExecutorService ) { ExecutorService executorService = ( ExecutorService ) executor ; future = executorService . submit ( runnable ) ; } else { executor . execute ( runnable ) ; } } return future ; }
execute a runnable after the given delay .
