Logo

Programming-Idioms

History of Idiom 185 > diff from v7 to v8

Edit summary for version 8 by m@:
New Java implementation by user [m@]

Version 7

2019-09-09, 09:05:01

Version 8

2019-09-26, 14:06:31

Idiom #185 Execute function in 30 seconds

Schedule the execution of f(42) in 30 seconds.

Idiom #185 Execute function in 30 seconds

Schedule the execution of f(42) in 30 seconds.

Extra Keywords
future
Extra Keywords
future
Imports
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
Code
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
executorService.schedule(() -> _f(42), delayInSeconds, TimeUnit.SECONDS);
Doc URL
https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ScheduledExecutorService.html
Origin
https://www.baeldung.com/java-delay-code-execution