For Java 11 Certification Exam Practice Questions, refer

In this article, let us discuss the ScheduledExecutorService in Java, from the Java 11 certification perspective.

What is ScheduledExecutorService?

The java.util.concurrent.ScheduledExecutorService is an implementation of ExecutorService that can be used to schedule tasks to run after a delay, or to execute repeatedly with a fixed time interval between each execution. A worker thread from a thread pool executes the tasks asynchronously.

Here is an example to show how it works.

ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
ScheduledFuture scheduledFuture = scheduledExecutorService.schedule(new Callable() 
	    public Object call() throws Exception {
		return "Called!";
}, 15, TimeUnit.SECONDS);

In the above code, the message “Called!” is printed after a delay of 15 seconds.


For more information on this topic, you can refer

Leave a Reply

Your email address will not be published. Required fields are marked *