本文整理了Java中org.springframework.scheduling.TaskScheduler.scheduleAtFixedRate()
方法的一些代码示例,展示了TaskScheduler.scheduleAtFixedRate()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TaskScheduler.scheduleAtFixedRate()
方法的具体详情如下:
包路径:org.springframework.scheduling.TaskScheduler
类名称:TaskScheduler
方法名:scheduleAtFixedRate
[英]Schedule the given Runnable, starting as soon as possible and invoking it with the given period.
Execution will end once the scheduler shuts down or the returned ScheduledFuture gets cancelled.
[中]安排给定的Runnable,尽快开始并在给定的时间段内调用它。
一旦调度程序关闭或返回的ScheduledFuture被取消,执行将结束。
代码示例来源:origin: spring-projects/spring-framework
/**
* Schedule the given {@link Runnable}, starting as soon as possible and
* invoking it with the given period.
* <p>Execution will end once the scheduler shuts down or the returned
* {@link ScheduledFuture} gets cancelled.
* @param task the Runnable to execute whenever the trigger fires
* @param period the interval between successive executions of the task
* @return a {@link ScheduledFuture} representing pending completion of the task
* @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
* @since 5.0
* @see #scheduleAtFixedRate(Runnable, long)
*/
default ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Duration period) {
return scheduleAtFixedRate(task, period.toMillis());
}
代码示例来源:origin: spring-projects/spring-security
@Override
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Date startTime, long period) {
return taskScheduler.scheduleAtFixedRate(task, startTime, period);
}
代码示例来源:origin: spring-projects/spring-security
@Override
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long period) {
return taskScheduler.scheduleAtFixedRate(task, period);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Schedule the given {@link Runnable}, invoking it at the specified execution time
* and subsequently with the given period.
* <p>Execution will end once the scheduler shuts down or the returned
* {@link ScheduledFuture} gets cancelled.
* @param task the Runnable to execute whenever the trigger fires
* @param startTime the desired first execution time for the task
* (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
* @param period the interval between successive executions of the task
* @return a {@link ScheduledFuture} representing pending completion of the task
* @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
* @since 5.0
* @see #scheduleAtFixedRate(Runnable, Date, long)
*/
default ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Instant startTime, Duration period) {
return scheduleAtFixedRate(task, Date.from(startTime), period.toMillis());
}
代码示例来源:origin: org.springframework/spring-context
/**
* Schedule the given {@link Runnable}, starting as soon as possible and
* invoking it with the given period.
* <p>Execution will end once the scheduler shuts down or the returned
* {@link ScheduledFuture} gets cancelled.
* @param task the Runnable to execute whenever the trigger fires
* @param period the interval between successive executions of the task
* @return a {@link ScheduledFuture} representing pending completion of the task
* @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
* @since 5.0
* @see #scheduleAtFixedRate(Runnable, long)
*/
default ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Duration period) {
return scheduleAtFixedRate(task, period.toMillis());
}
代码示例来源:origin: org.springframework/spring-context
/**
* Schedule the given {@link Runnable}, invoking it at the specified execution time
* and subsequently with the given period.
* <p>Execution will end once the scheduler shuts down or the returned
* {@link ScheduledFuture} gets cancelled.
* @param task the Runnable to execute whenever the trigger fires
* @param startTime the desired first execution time for the task
* (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
* @param period the interval between successive executions of the task
* @return a {@link ScheduledFuture} representing pending completion of the task
* @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
* @since 5.0
* @see #scheduleAtFixedRate(Runnable, Date, long)
*/
default ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Instant startTime, Duration period) {
return scheduleAtFixedRate(task, Date.from(startTime), period.toMillis());
}
代码示例来源:origin: spring-projects/spring-framework
private void scheduleSessionTask() {
synchronized (this.sessions) {
if (this.sessionCleanupTask != null) {
return;
}
this.sessionCleanupTask = getTaskScheduler().scheduleAtFixedRate(() -> {
List<String> removedIds = new ArrayList<>();
for (SockJsSession session : this.sessions.values()) {
try {
if (session.getTimeSinceLastActive() > getDisconnectDelay()) {
this.sessions.remove(session.getId());
removedIds.add(session.getId());
session.close();
}
}
catch (Throwable ex) {
// Could be part of normal workflow (e.g. browser tab closed)
logger.debug("Failed to close " + session, ex);
}
}
if (logger.isDebugEnabled() && !removedIds.isEmpty()) {
logger.debug("Closed " + removedIds.size() + " sessions: " + removedIds);
}
}, getDisconnectDelay());
}
}
代码示例来源:origin: spring-projects/spring-framework
Date startTime = new Date(System.currentTimeMillis() + task.getInitialDelay());
scheduledTask.future =
this.taskScheduler.scheduleAtFixedRate(task.getRunnable(), startTime, task.getInterval());
this.taskScheduler.scheduleAtFixedRate(task.getRunnable(), task.getInterval());
代码示例来源:origin: org.springframework/spring-context
Date startTime = new Date(System.currentTimeMillis() + task.getInitialDelay());
scheduledTask.future =
this.taskScheduler.scheduleAtFixedRate(task.getRunnable(), startTime, task.getInterval());
this.taskScheduler.scheduleAtFixedRate(task.getRunnable(), task.getInterval());
代码示例来源:origin: spring-projects/spring-security
@Test
public void testScheduleAtFixedRateWithRunnableAndDate() {
Date date = new Date(1544751374L);
Duration duration = Duration.ofSeconds(4L);
delegatingSecurityContextTaskScheduler.scheduleAtFixedRate(runnable, date, 1000L);
verify(scheduler).scheduleAtFixedRate(isA(Runnable.class), isA(Date.class), eq(1000L));
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void testScheduleAtFixedRateWithRunnableAndLong() {
delegatingSecurityContextTaskScheduler.scheduleAtFixedRate(runnable, 1000L);
verify(scheduler).scheduleAtFixedRate(isA(Runnable.class), eq(1000L));
}
}
代码示例来源:origin: Netflix/genie
/**
* {@inheritDoc}
*/
@Override
public synchronized void start(@NotBlank final String jobId) {
if (StringUtils.isNotBlank(this.claimedJobId)) {
throw new IllegalStateException("Previously started with a different job id");
}
this.claimedJobId = jobId;
this.heartBeatMessage = AgentHeartBeat.newBuilder()
.setClaimedJobId(claimedJobId)
.build();
this.heartbeatFuture = taskScheduler.scheduleAtFixedRate(
this::sendHeartBeatTask,
HEART_BEAT_PERIOD_MILLIS
);
this.requestObserver = client.heartbeat(new ResponseObserver(this));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void handleTransportRequestXhr() throws Exception {
String sockJsPath = sessionUrlPrefix + "xhr";
setRequest("POST", sockJsPrefix + sockJsPath);
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
assertEquals(200, this.servletResponse.getStatus());
verify(this.xhrHandler).handleRequest(this.request, this.response, this.wsHandler, this.session);
verify(taskScheduler).scheduleAtFixedRate(any(Runnable.class), eq(service.getDisconnectDelay()));
assertEquals("no-store, no-cache, must-revalidate, max-age=0", this.response.getHeaders().getCacheControl());
assertNull(this.servletResponse.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
assertNull(this.servletResponse.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS));
}
代码示例来源:origin: org.springframework.boot/spring-boot-actuator
/**
* Create a new {@link PrometheusPushGatewayManager} instance.
* @param pushGateway the source push gateway
* @param registry the collector registry to push
* @param scheduler the scheduler used for operations
* @param pushRate the rate at which push operations occur
* @param job the job ID for the operation
* @param groupingKey an optional set of grouping keys for the operation
* @param shutdownOperation the shutdown operation that should be performed when
* context is closed.
*/
public PrometheusPushGatewayManager(PushGateway pushGateway,
CollectorRegistry registry, TaskScheduler scheduler, Duration pushRate,
String job, Map<String, String> groupingKey,
ShutdownOperation shutdownOperation) {
Assert.notNull(pushGateway, "PushGateway must not be null");
Assert.notNull(registry, "Registry must not be null");
Assert.notNull(scheduler, "Scheduler must not be null");
Assert.notNull(pushRate, "PushRate must not be null");
Assert.hasLength(job, "Job must not be empty");
this.pushGateway = pushGateway;
this.registry = registry;
this.job = job;
this.groupingKey = groupingKey;
this.shutdownOperation = (shutdownOperation != null) ? shutdownOperation
: ShutdownOperation.NONE;
this.scheduler = scheduler;
this.scheduled = this.scheduler.scheduleAtFixedRate(this::push, pushRate);
}
代码示例来源:origin: spring-projects/spring-integration
@Override
public void start() {
if (this.flushTask == null && FileExistsMode.APPEND_NO_FLUSH.equals(this.fileExistsMode)) {
TaskScheduler taskScheduler = getTaskScheduler();
Assert.state(taskScheduler != null, "'taskScheduler' is required for FileExistsMode.APPEND_NO_FLUSH");
this.flushTask = taskScheduler.scheduleAtFixedRate(new Flusher(), this.flushInterval / 3); // NOSONAR
}
}
代码示例来源:origin: spring-projects/spring-integration
@Override
public void start() {
synchronized (this.lifecycleMonitor) {
if (!this.active) {
this.active = true;
if (this.clientConnectionFactory != null) {
this.clientConnectionFactory.start();
}
if (this.serverConnectionFactory != null) {
this.serverConnectionFactory.start();
}
if (this.isClientMode) {
Assert.notNull(this.clientConnectionFactory,
"For client-mode, connection factory must be type='client'");
ClientModeConnectionManager manager =
new ClientModeConnectionManager(this.clientConnectionFactory);
this.clientModeConnectionManager = manager;
Assert.state(getTaskScheduler() != null, "Client mode requires a task scheduler");
this.scheduledFuture = getTaskScheduler().scheduleAtFixedRate(manager, this.retryInterval);
}
}
}
}
代码示例来源:origin: spring-projects/spring-integration
@Override // protected by super#lifecycleLock
protected void doStart() {
super.doStart();
if (!this.active) {
this.active = true;
this.shuttingDown = false;
if (this.serverConnectionFactory != null) {
this.serverConnectionFactory.start();
}
if (this.clientConnectionFactory != null) {
this.clientConnectionFactory.start();
}
if (this.isClientMode) {
ClientModeConnectionManager manager = new ClientModeConnectionManager(
this.clientConnectionFactory);
this.clientModeConnectionManager = manager;
Assert.state(this.getTaskScheduler() != null, "Client mode requires a task scheduler");
this.scheduledFuture = this.getTaskScheduler().scheduleAtFixedRate(manager, this.retryInterval);
}
}
}
代码示例来源:origin: spring-projects/spring-integration
@Override // protected by super#lifecycleLock
protected void doStart() {
super.doStart();
if (!this.active) {
this.active = true;
this.shuttingDown = false;
if (this.serverConnectionFactory != null) {
this.serverConnectionFactory.start();
}
if (this.clientConnectionFactory != null) {
this.clientConnectionFactory.start();
}
if (this.isClientMode) {
ClientModeConnectionManager manager = new ClientModeConnectionManager(
this.clientConnectionFactory);
this.clientModeConnectionManager = manager;
Assert.state(this.getTaskScheduler() != null, "Client mode requires a task scheduler");
this.scheduledFuture = this.getTaskScheduler().scheduleAtFixedRate(manager, this.retryInterval);
}
}
}
代码示例来源:origin: spring-projects/spring-integration
this.idleTask = getTaskScheduler().scheduleAtFixedRate(new IdleContainerStopper(),
this.idleReplyContainerTimeout / 2);
代码示例来源:origin: spring-cloud/spring-cloud-consul
/**
* Add a service to the checks loop.
*/
public void add(String instanceId) {
ScheduledFuture task = scheduler.scheduleAtFixedRate(new ConsulHeartbeatTask(
instanceId), configuration.computeHearbeatInterval()
.toStandardDuration().getMillis());
ScheduledFuture previousTask = serviceHeartbeats.put(instanceId, task);
if (previousTask != null) {
previousTask.cancel(true);
}
}
内容来源于网络,如有侵权,请联系作者删除!