Code example for ScheduledExecutorService

Methods: schedule

-7
			/* no serial, but a delay: schedule the task */ 
			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 { 
				/* non-cancellable task */ 
				executor.execute(runnable);
			} 
		} 
		return future;
	} 
 
	/** 
	 * Execute a task after (at least) its delay <strong>and</strong> after all 
	 * tasks added with the same non-null <code>serial</code> (if any) have