This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
executorService.schedule(() -> _f(42), delayInSeconds, TimeUnit.SECONDS);
Thread t = new Thread(() -> {
try {
sleep(30_000);
f(42);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
t.start();
my $thr = threads->create(sub { sleep(30); f(42); });
$thr->join()
join() waits for $thr to finish
my $thr = threads->create(sub { sleep(30); f(42); });
$thr->detach();
Uses Perl 5.6 threads. Note that if the main program exits without having join()ed the thread, the thread will be killed.
local $SIG{ALRM} = sub { f(42) };
alarm 30;
Attach a handler to an alarm signal. Then ask the OS to deliver the signal in thirty seconds. NOTE: can handle only one delayed task at a time.