use of org.springframework.scheduling.annotation.Scheduled in project spring-boot-starter-samples by vindell.
the class DisruptorConfig method send.
// 每1s执行1次
@Scheduled(fixedDelay = 1000)
public void send() throws Exception {
DisruptorBindEvent event = new DisruptorBindEvent(this, "message " + Math.random());
event.setEvent("Event-Output");
event.setTag("TagA-Output");
event.setKey("id-" + Math.random());
disruptorTemplate.publishEvent(event);
}
use of org.springframework.scheduling.annotation.Scheduled in project webapp by elimu-ai.
the class LetterUsageCountScheduler method execute.
// At 06:15 every day
@Scheduled(cron = "00 15 06 * * *")
public synchronized void execute() {
logger.info("execute");
logger.info("Calculating usage count for Letters");
Map<String, Integer> letterFrequencyMap = new HashMap<>();
Language language = Language.valueOf(ConfigHelper.getProperty("content.language"));
List<StoryBook> storyBooks = storyBookDao.readAllOrdered();
logger.info("storyBooks.size(): " + storyBooks.size());
for (StoryBook storyBook : storyBooks) {
logger.info("storyBook.getTitle(): " + storyBook.getTitle());
List<String> paragraphs = new ArrayList<>();
List<StoryBookChapter> storyBookChapters = storyBookChapterDao.readAll(storyBook);
for (StoryBookChapter storyBookChapter : storyBookChapters) {
List<StoryBookParagraph> storyBookParagraphs = storyBookParagraphDao.readAll(storyBookChapter);
for (StoryBookParagraph storyBookParagraph : storyBookParagraphs) {
paragraphs.add(storyBookParagraph.getOriginalText());
}
}
Map<String, Integer> letterFrequencyMapForBook = LetterFrequencyHelper.getLetterFrequency(paragraphs, language);
letterFrequencyMapForBook.keySet().forEach(letterText -> letterFrequencyMap.put(letterText, letterFrequencyMap.getOrDefault(letterText, 0) + letterFrequencyMapForBook.get(letterText)));
}
logger.info("letterFrequencyMap: " + letterFrequencyMap);
for (String letterText : letterFrequencyMap.keySet()) {
Letter existingLetter = letterDao.readByText(letterText);
if (existingLetter != null) {
existingLetter.setUsageCount(letterFrequencyMap.get(letterText));
letterDao.update(existingLetter);
}
}
logger.info("execute complete");
}
use of org.springframework.scheduling.annotation.Scheduled in project webapp by elimu-ai.
the class SoundUsageCountScheduler method execute.
// At 06:30 every day
@Scheduled(cron = "00 30 06 * * *")
public synchronized void execute() {
logger.info("execute");
logger.info("Calculating usage count of Sounds");
// Long = Sound ID
// Integer = Usage count
Map<Long, Integer> soundFrequencyMap = new HashMap<>();
// Summarize the usage count of each Word's Sounds based on the LetterSoundCorrespondence's
// usage count (see LetterSoundCorrespondenceUsageCountScheduler).
List<Word> words = wordDao.readAllOrdered();
logger.info("words.size(): " + words.size());
for (Word word : words) {
for (LetterSoundCorrespondence letterSoundCorrespondence : word.getLetterSoundCorrespondences()) {
for (Sound sound : letterSoundCorrespondence.getSounds()) {
soundFrequencyMap.put(sound.getId(), soundFrequencyMap.getOrDefault(sound.getId(), 0) + letterSoundCorrespondence.getUsageCount());
}
}
}
// Update each Sound's usage count in the database
for (Long soundId : soundFrequencyMap.keySet()) {
Sound sound = soundDao.read(soundId);
sound.setUsageCount(soundFrequencyMap.get(soundId));
soundDao.update(sound);
}
logger.info("execute complete");
}
use of org.springframework.scheduling.annotation.Scheduled in project webapp by elimu-ai.
the class WordUsageCountScheduler method execute.
// At 06:00 every day
@Scheduled(cron = "00 00 06 * * *")
public synchronized void execute() {
logger.info("execute");
logger.info("Calculating usage count for Words");
Map<String, Integer> wordFrequencyMap = new HashMap<>();
Language language = Language.valueOf(ConfigHelper.getProperty("content.language"));
List<StoryBook> storyBooks = storyBookDao.readAllOrdered();
logger.info("storyBooks.size(): " + storyBooks.size());
for (StoryBook storyBook : storyBooks) {
logger.info("storyBook.getTitle(): " + storyBook.getTitle());
List<String> paragraphs = new ArrayList<>();
List<StoryBookChapter> storyBookChapters = storyBookChapterDao.readAll(storyBook);
for (StoryBookChapter storyBookChapter : storyBookChapters) {
List<StoryBookParagraph> storyBookParagraphs = storyBookParagraphDao.readAll(storyBookChapter);
for (StoryBookParagraph storyBookParagraph : storyBookParagraphs) {
paragraphs.add(storyBookParagraph.getOriginalText());
}
}
Map<String, Integer> wordFrequencyMapForBook = WordFrequencyHelper.getWordFrequency(paragraphs, language);
wordFrequencyMapForBook.keySet().forEach(word -> wordFrequencyMap.put(word, wordFrequencyMap.getOrDefault(word, 0) + wordFrequencyMapForBook.get(word)));
}
for (String key : wordFrequencyMap.keySet()) {
String wordLowerCase = key.toLowerCase();
logger.info("wordLowerCase: \"" + wordLowerCase + "\"");
Word word = wordDao.readByText(wordLowerCase);
if (word != null) {
word.setUsageCount(wordFrequencyMap.get(wordLowerCase));
wordDao.update(word);
}
}
logger.info("execute complete");
}
use of org.springframework.scheduling.annotation.Scheduled in project summer by foxsugar.
the class ScheduledService method scheduled.
/**
* 每天5点 定时删除游戏记录
*/
@Scheduled(cron = "0 0 5 ? * *")
public void scheduled() {
if (SpringUtil.getBean(ServerConfig.class).getDeleteRecordTask() == 1) {
logger.info("=====>>>>>定时任务 删除游戏记录 {}", System.currentTimeMillis());
LocalDate date = LocalDate.now();
date = date.minusDays(7);
ZoneId zoneId = ZoneId.systemDefault();
ZonedDateTime zdt = date.atStartOfDay(zoneId);
Date d = Date.from(zdt.toInstant());
gameRecordService.gameRecordDao.deleteAllByDateBefore(d);
gameRecordService.replayDao.deleteAllByDateBefore(d);
}
// if (SpringUtil.getBean(ServerConfig.class).getLoadAllUser() == 1) {
// LocalDate yestoday = LocalDate.now().minusDays(1);
// String ys = yestoday.toString();
// // ys = LocalDate.now().toString();
// for(String uid : RedisManager.getUserRedisService().getAllUserId()){
// long userId = Long.valueOf(uid);
// UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
// if (userBean.getVip() > 1 && userBean.getReferee() != 0) {
//
// Double lastDayRebate = rebateDetailService.rebateDetailDao.getRebateByDate(userId, ys);
// if (lastDayRebate != null) {
//
// double re = lastDayRebate /10;
//
// UserBean parent = RedisManager.getUserRedisService().getUserBean(userBean.getReferee());
// parent.getUserInfo().setAllRebate(parent.getUserInfo().getAllRebate() + re);
// RedisManager.getUserRedisService().updateUserBean(parent.getId(), parent);
//
// //返利记录
// RebateDetail rebateDetail = new RebateDetail();
// rebateDetail.setNum(re);
// rebateDetail.setUserId(userBean.getId());
// rebateDetail.setAgentId(parent.getId());
// rebateDetail.setDate(new Date());
// rebateDetail.setType(1);
//
// rebateDetailService.rebateDetailDao.save(rebateDetail);
// }
// }
// }
// // rebateDetailService.rebateDetailDao.findAllByAgentId()
//
// LocalDate localDate = LocalDate.now().minusDays(8);
// rebateDetailService.rebateDetailDao.deleteAllByDateBefore(DateUtil.convertDay2Date(localDate.toString()));
// }
}
Aggregations