Code example for ScheduledExecutorService

Methods: scheduleAtFixedRate

0
    public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay,
                                                  long period, TimeUnit unit) {
        if (ses == null)
            ses = Executors.newScheduledThreadPool(1);
        try { 
            return ses.scheduleAtFixedRate(command, initialDelay, period, unit);
        } catch (Exception e) {
            return new MockFuture<Object>(new ExecutionException(e));
        } 
    } 
 
    @Override 
    public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay,
                                                     long delay, TimeUnit unit) {
        if (ses == null)
            ses = Executors.newScheduledThreadPool(1);
        try { 
            return ses.scheduleWithFixedDelay(command, initialDelay, delay, unit);
        } catch (Exception e) {
            return new MockFuture<Object>(new ExecutionException(e));
Experience pair programming with AI  Get Codota for Java