当前位置: 首页>>代码示例>>Java>>正文


Java Scheduled类代码示例

本文整理汇总了Java中org.springframework.scheduling.annotation.Scheduled的典型用法代码示例。如果您正苦于以下问题:Java Scheduled类的具体用法?Java Scheduled怎么用?Java Scheduled使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Scheduled类属于org.springframework.scheduling.annotation包,在下文中一共展示了Scheduled类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: indexedData

import org.springframework.scheduling.annotation.Scheduled; //导入依赖的package包/类
@HystrixCommand(fallbackMethod = HYSTRIX_FALL_BACK,
        commandKey = HYSTRIX_COMMAND_KEY,
        groupKey = HYSTRIX_GROUP_KEY)
@Scheduled(fixedDelay = 60000)
public void indexedData() {

    log.info("SEARCH-SERVICE: Data indexer is starting to work.");

    currentPageIndex = getCurrentPageIndex();

    log.info("Current page for pushing is {}", currentPageIndex);

    long totalPage = tweetClient.getTweets().getMetadata().getTotalPages();

    for (long i = currentPageIndex; i <= totalPage; i++) {
        Runnable task = new PusherProcessor(tweetRepository, tweetClient, i);
        taskExecutor.execute(task);

        currentPageIndex = i++;

        saveCurrentPageIndex(i);
    }
}
 
开发者ID:thinksky-sourcecode,项目名称:microservices-prototype,代码行数:24,代码来源:DataService.java

示例2: execute

import org.springframework.scheduling.annotation.Scheduled; //导入依赖的package包/类
@Scheduled(cron = "0/10 * * * * ?")
public void execute() throws Exception {
    logger.info("start");

    List<Task> tasks = processEngine.getTaskService().createTaskQuery()
            .list();

    for (Task task : tasks) {
        if (task.getDueDate() != null) {
            SendNoticeCmd sendNoticeCmd = new SendNoticeCmd(task.getId());
            processEngine.getManagementService().executeCommand(
                    sendNoticeCmd);
        }
    }

    logger.info("end");
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:18,代码来源:TaskTimeoutJob.java

示例3: purgeOldNotifications

import org.springframework.scheduling.annotation.Scheduled; //导入依赖的package包/类
@Scheduled(fixedRate = 60000)
@Transactional
public void purgeOldNotifications() {
	ExpirationConfiguration props = properties.getNotifications();
	String methodName = "purgeOldNotifications";
	PurgeMethods purgeMethod = new PurgeMethods() {

		@Override
		public long deleteByTime(long time) {
			return notRepo.deleteByTimeLessThanOrderByTimeDesc(time);
		}

		@Override
		public long deleteBySize(long max) {
			return 0;
		}
		
	};
	purgeData(methodName, props, purgeMethod);
}
 
开发者ID:mshaw323,项目名称:stdds-monitor,代码行数:21,代码来源:DataScheduler.java

示例4: sessionTimeoutTask

import org.springframework.scheduling.annotation.Scheduled; //导入依赖的package包/类
@Override
@Transactional(propagation = Propagation.NEVER)
@Scheduled(initialDelay = 10 * 1000, fixedDelay = SESSION_TIMEOUT_TASK_HEARTBEAT)
public void sessionTimeoutTask() {
    if (!taskConfig.isEnableAgentSessionTimeoutTask()) {
        return;
    }

    LOGGER.traceMarker("sessionTimeoutTask", "start");
    ZonedDateTime now = DateUtil.utcNow();

    for (Zone zone : zoneService.getZones()) {
        Collection<Agent> agents = listForOnline(zone.getName());
        for (Agent agent : agents) {
            if (agent.getSessionId() != null && isSessionTimeout(agent, now, zone.getAgentSessionTimeout())) {
                Cmd delSessionCmd = cmdService.create(new CmdInfo(agent.getPath(), CmdType.DELETE_SESSION, null));
                cmdDispatchService.dispatch(delSessionCmd);
                LOGGER.traceMarker("sessionTimeoutTask", "Send DELETE_SESSION to agent %s", agent);
            }
        }
    }

    LOGGER.traceMarker("sessionTimeoutTask", "end");
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:25,代码来源:AgentServiceImpl.java

示例5: insertCoinbaseQuote

import org.springframework.scheduling.annotation.Scheduled; //导入依赖的package包/类
@Scheduled(fixedRate = 60000, initialDelay=15000)
	public void insertCoinbaseQuote() {
		Date start = new Date();
		WebClient wc = buildWebClient(URLCB);
		try {
			operations.insert(
					wc.get().uri("/exchange-rates?currency=BTC")
	                .accept(MediaType.APPLICATION_JSON).exchange()
	                .flatMap(response ->	response.bodyToMono(WrapperCb.class))
	                .flatMap(resp -> Mono.just(resp.getData()))
	                .flatMap(resp2 -> {log.info(resp2.getRates().toString()); return Mono.just(resp2.getRates());})
					).then().block(Duration.ofSeconds(3));
			log.info("CoinbaseQuote " + dateFormat.format(new Date()) + " " + (new Date().getTime()-start.getTime()) + "ms");
		} catch (Exception e) {
//			log.error("Coinbase insert error", e);
			log.error("Coinbase insert error "+ dateFormat.format(new Date()));
		}
	}
 
开发者ID:Angular2Guy,项目名称:AngularAndSpring,代码行数:19,代码来源:ScheduledTask.java

示例6: execute

import org.springframework.scheduling.annotation.Scheduled; //导入依赖的package包/类
@Scheduled(fixedDelay = 60 * 1000)
public void execute() {
	Date date = DateUtils.parse(DateUtils.format(new Date(), DateUtils.PATTERN_SIMPLE_DATE),
			DateUtils.PATTERN_SIMPLE_DATE);
	if (date.compareTo(this.date) > 0) {
		this.date = date;
		cache.clear();
	}

	String accessToken = getAccessToken();
	scheduleRepository.findByDate(date).forEach(s -> {
		if (cache.contains(new Long(s.getScheduleId().intValue()))) {
			return;
		}
		if (isNeedSendMessageNow(s)) {
			doSend(accessToken, s);
			cache.add(new Long(s.getScheduleId().intValue()));
		}
	});
}
 
开发者ID:7upcat,项目名称:agile-wroking-backend,代码行数:21,代码来源:SendNotifyMessageJob.java

示例7: buildJwks

import org.springframework.scheduling.annotation.Scheduled; //导入依赖的package包/类
/**
 * Builds JWKS if necessary after 60 seconds, but only builds
 * {@value #MIN_NUMBER_OF_KEYS} at a time.
 */
@Scheduled(fixedDelay = 60000)
public void buildJwks() {

    int nCreated = 0;
    for (int i = 0; i < MAX_NUMBER_OF_KEYS; ++i) {
        final String cacheKey = String.valueOf(i);
        final JsonWebKey jwk = jwksCache.get(cacheKey, JsonWebKey.class);
        if (jwk == null && nCreated < MIN_NUMBER_OF_KEYS) {
            final RsaJsonWebKey newJwk = buildNewRsaKey();
            jwksCache.putIfAbsent(cacheKey, newJwk);
            ++nCreated;
            LOG.debug("Created new JWK kid={}", newJwk.getKeyId());
        }
    }

}
 
开发者ID:trajano,项目名称:app-ms,代码行数:21,代码来源:CachedDataProvider.java

示例8: process

import org.springframework.scheduling.annotation.Scheduled; //导入依赖的package包/类
/**
 * Process all instance days that are not processed already, but are due
 *
 * “At minute 0 past every hour.”
 */
@Scheduled(cron = "${biblereadingplan.postservice.cron:0 0 */1 * * *}")
@Transactional
public void process() {
    validateService.scheduleAll();
    for (PlanInstanceDay instanceDay : planInstanceDayRepository
            .findAllByIsPostedIsFalseAndScheduledDateBeforeOrderByScheduledDateAsc(new Date())) {
        validateService.setDefaultValues(instanceDay.getDay());
        validateService.setDefaultValues(instanceDay);
        if (rocketChatPostService.post(instanceDay)) {
            instanceDay.setPosted(true);
            planInstanceDayRepository.save(instanceDay);
        } else {
            LOGGER.error("Could not post message.");
        }
    }
}
 
开发者ID:sscholl,项目名称:biblebot,代码行数:22,代码来源:PostService.java

示例9: storeUserCountMetrics

import org.springframework.scheduling.annotation.Scheduled; //导入依赖的package包/类
@Scheduled(cron = "10 * * * * ?")
void storeUserCountMetrics() {
    ZonedDateTime timestamp = ZonedDateTime.now().truncatedTo(MINUTES);

    userCountRepository.save(
        metricRegistry.getHistograms((name, metric) -> name.startsWith("discord.ws.users"))
            .entrySet().stream()
            .map(entry -> Pair.of(extractTags(entry.getKey()), (long) entry.getValue().getSnapshot().getMean()))
            .map(pair -> new UserCount()
                .bot(pair.getKey()[0])
                .guild(pair.getKey()[1])
                .status(pair.getKey()[2])
                .value(pair.getValue())
                .timestamp(timestamp))
            .collect(Collectors.toList())
    );
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:18,代码来源:UserCountService.java

示例10: autoCancel

import org.springframework.scheduling.annotation.Scheduled; //导入依赖的package包/类
/**
 */
@Scheduled(fixedRate = 10000)
public void autoCancel() {
	// 获取过期的资源
	final List<ProuctTcc> tccs = productTccRepositorie.expireReservation(2);
	tccs.forEach(tcc -> {
		cancel(tcc.getId());
	});
}
 
开发者ID:zhaoqilong3031,项目名称:spring-cloud-samples,代码行数:11,代码来源:ProductService.java

示例11: killHLSStreams

import org.springframework.scheduling.annotation.Scheduled; //导入依赖的package包/类
@Scheduled(fixedDelay = 5 * 1000)//Every 5 seconds
public void killHLSStreams() {
    long now = new Date().getTime();
    Map<Thread, IStreamTask> HLSTasksFore = new HashMap(HLSTasks);
    for (Entry<Thread, IStreamTask> entry : HLSTasksFore.entrySet()) {
        HLSTask hlsTask = (HLSTask) entry.getValue();
        if (hlsTask.getLastAccess() != null) {
            long difference = (now - hlsTask.getLastAccess()) / 1000;
            if (difference > config.getFfmpeg().getHls().getTimeout()) {
                //Kill all stream processors using this task
                for (ClientInfo client : new ArrayList<>(streamProcessorsSession.getClientInfoList())) {
                    for (IStreamProcessor streamProcessor : new ArrayList<>(client.getStreams())) {
                        IStreamTask streamBindedTask = streamProcessor.getTask();
                        if (streamBindedTask == hlsTask) {
                            try {
                                streamProcessor.stop(false);
                                streamProcessorsSession.removeClientInfo(client, streamProcessor);
                            } catch (Exception ex) {
                            }
                        }
                    }
                }
            }
        }

    }
}
 
开发者ID:segator,项目名称:proxylive,代码行数:28,代码来源:ProcessorTasks.java

示例12: upload

import org.springframework.scheduling.annotation.Scheduled; //导入依赖的package包/类
/**
 * 上传到hdfs并删除相应的文件
 */
@Scheduled(cron = "${spring.upload.log.cron}")
private void upload() {
    String yesterday = this.getYesterday();
    LOGGER.info("开始上传到hdfs, 时间: {}", yesterday);
    StopWatch sw = new StopWatch();
    sw.start();
    this.fileUtil.uploadToHDFS(yesterday);
    sw.stop();
    LOGGER.info("上传到hdfs结束, 耗时: {} ms", sw.getTotalTimeMillis());
}
 
开发者ID:JThink,项目名称:SkyEye,代码行数:14,代码来源:UploadTask.java

示例13: daily

import org.springframework.scheduling.annotation.Scheduled; //导入依赖的package包/类
@Scheduled(cron = "0 5 8 * * *")
public void daily() {
    long start = System.currentTimeMillis();
    log.info("每日精选启动...");

    try {
        String date = DateFormatUtils.format(new Date(), pattern);
        fanfouHandler.sendContent(dailyChatId, AppUtils.getFanFouDailyByDate(date));
    } catch (Exception e) {
        log.info(e.getMessage());
        appUtils.sendServerChan(e.getMessage(), ExceptionUtils.getStackTrace(e));
    }

    log.info("每日精选完成,耗时:{} ms", System.currentTimeMillis() - start);
}
 
开发者ID:junbaor,项目名称:telegram-bot,代码行数:16,代码来源:FanfouTask.java

示例14: simulateActivity

import org.springframework.scheduling.annotation.Scheduled; //导入依赖的package包/类
@Scheduled(fixedRate = 100)
public void simulateActivity() {
	repository
		.findAll()
		.map(image -> {
			Comment comment = new Comment();
			comment.setImageId(image.getId());
			comment.setComment(
				"Comment #" + counter.getAndIncrement());
			return Mono.just(comment);
		})
		.map(commentController::addComment)
		.subscribe();
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:15,代码来源:CommentSimulator.java

示例15: tokenRepositoryCleaner

import org.springframework.scheduling.annotation.Scheduled; //导入依赖的package包/类
@Scheduled(fixedRate = 600_000)
public void tokenRepositoryCleaner(){
    Thread trct = new Thread(
            new JpaTokenRepositoryCleaner(
                    rememberMeTokenRepository,
                    100_000L));
    trct.start();
}
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:9,代码来源:JavaConfig.java


注:本文中的org.springframework.scheduling.annotation.Scheduled类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。