O'Reilly logo

Java 9 Concurrency Cookbook - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The key point of this example is the Main class and the management of ScheduledThreadPoolExecutor. As with the ThreadPoolExecutor class, to create a scheduled executor, Java recommends that you utilize the Executors class. In this case, you used the newScheduledThreadPool() method. You passed the number 1 as a parameter to this method. This parameter refers to the number of threads you want to have in the pool.

To execute a task in this scheduled executor after a period of time, you have to use the schedule() method. This method receives the following three parameters:

  • The task you want to execute
  • The period of time you want the task to wait before its execution
  • The unit of the period of time, specified as a constant of the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required