Java Code Examples for javax.enterprise.concurrent.ManagedScheduledExecutorService#schedule()

The following examples show how to use javax.enterprise.concurrent.ManagedScheduledExecutorService#schedule() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ManagedScheduledExecutorServiceTest.java    From tomee with Apache License 2.0 7 votes vote down vote up
@Test
public void simpleSchedule() throws Exception {
    final ManagedScheduledExecutorService es = new ManagedScheduledExecutorServiceImplFactory().create();
    final long start = System.currentTimeMillis();
    final ScheduledFuture<Long> future = es.schedule(new Callable<Long>() {
        @Override
        public Long call() throws Exception {
            Thread.sleep(4000);
            return System.currentTimeMillis();
        }
    }, 2, TimeUnit.SECONDS);
    assertEquals(6, TimeUnit.MILLISECONDS.toSeconds(future.get() - start), 1);
}
 
Example 2
Source File: ConcurrentTaskScheduler.java    From spring-analysis-note with MIT License 6 votes vote down vote up
public ScheduledFuture<?> schedule(Runnable task, final Trigger trigger) {
	ManagedScheduledExecutorService executor = (ManagedScheduledExecutorService) scheduledExecutor;
	return executor.schedule(task, new javax.enterprise.concurrent.Trigger() {
		@Override
		@Nullable
		public Date getNextRunTime(@Nullable LastExecution le, Date taskScheduledTime) {
			return (trigger.nextExecutionTime(le != null ?
					new SimpleTriggerContext(le.getScheduledStart(), le.getRunStart(), le.getRunEnd()) :
					new SimpleTriggerContext()));
		}
		@Override
		public boolean skipRun(LastExecution lastExecution, Date scheduledRunTime) {
			return false;
		}
	});
}
 
Example 3
Source File: ConcurrentTaskScheduler.java    From java-technology-stack with MIT License 6 votes vote down vote up
public ScheduledFuture<?> schedule(Runnable task, final Trigger trigger) {
	ManagedScheduledExecutorService executor = (ManagedScheduledExecutorService) scheduledExecutor;
	return executor.schedule(task, new javax.enterprise.concurrent.Trigger() {
		@Override
		@Nullable
		public Date getNextRunTime(@Nullable LastExecution le, Date taskScheduledTime) {
			return (trigger.nextExecutionTime(le != null ?
					new SimpleTriggerContext(le.getScheduledStart(), le.getRunStart(), le.getRunEnd()) :
					new SimpleTriggerContext()));
		}
		@Override
		public boolean skipRun(LastExecution lastExecution, Date scheduledRunTime) {
			return false;
		}
	});
}
 
Example 4
Source File: ConcurrentTaskScheduler.java    From audit4j-core with Apache License 2.0 6 votes vote down vote up
/**
 * Schedule.
 * 
 * @param task
 *            the task
 * @param trigger
 *            the trigger
 * @return the scheduled future
 */
public ScheduledFuture<?> schedule(Runnable task, final Trigger trigger) {
    ManagedScheduledExecutorService executor = (ManagedScheduledExecutorService) scheduledExecutor;
    return executor.schedule(task, new javax.enterprise.concurrent.Trigger() {
        @Override
        public Date getNextRunTime(LastExecution le, Date taskScheduledTime) {
            return trigger.nextExecutionTime(le != null ? new SimpleTriggerContext(le.getScheduledStart(), le
                    .getRunStart(), le.getRunEnd()) : new SimpleTriggerContext());
        }

        @Override
        public boolean skipRun(LastExecution lastExecution, Date scheduledRunTime) {
            return false;
        }
    });
}
 
Example 5
Source File: ConcurrentTaskScheduler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public ScheduledFuture<?> schedule(Runnable task, final Trigger trigger) {
	ManagedScheduledExecutorService executor = (ManagedScheduledExecutorService) scheduledExecutor;
	return executor.schedule(task, new javax.enterprise.concurrent.Trigger() {
		@Override
		public Date getNextRunTime(LastExecution le, Date taskScheduledTime) {
			return (trigger.nextExecutionTime(le != null ?
					new SimpleTriggerContext(le.getScheduledStart(), le.getRunStart(), le.getRunEnd()) :
					new SimpleTriggerContext()));
		}
		@Override
		public boolean skipRun(LastExecution lastExecution, Date scheduledRunTime) {
			return false;
		}
	});
}
 
Example 6
Source File: ConcurrentTaskScheduler.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public ScheduledFuture<?> schedule(Runnable task, final Trigger trigger) {
	ManagedScheduledExecutorService executor = (ManagedScheduledExecutorService) scheduledExecutor;
	return executor.schedule(task, new javax.enterprise.concurrent.Trigger() {
		@Override
		public Date getNextRunTime(LastExecution le, Date taskScheduledTime) {
			return trigger.nextExecutionTime(le != null ?
					new SimpleTriggerContext(le.getScheduledStart(), le.getRunStart(), le.getRunEnd()) :
					new SimpleTriggerContext());
		}
		@Override
		public boolean skipRun(LastExecution lastExecution, Date scheduledRunTime) {
			return false;
		}
	});
}