1.fix schedule task issue

main
Gary 11 months ago
parent b792b647f5
commit c90deee5c6

@ -21,10 +21,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
@ -85,25 +81,27 @@
<version>4.10.3</version>
</dependency>
<dependency>
<groupId>net.oschina.j2cache</groupId>
<artifactId>j2cache-spring-boot2-starter</artifactId>
<version>2.8.0-release</version>
</dependency>
<dependency>
<groupId>net.oschina.j2cache</groupId>
<artifactId>j2cache-core</artifactId>
<version>2.8.5-release</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<groupId>net.oschina.j2cache</groupId>
<artifactId>j2cache-spring-boot2-starter</artifactId>
<version>2.8.0-release</version>
</dependency>
<!-- j2cache依赖 -->
<dependency>
<groupId>net.oschina.j2cache</groupId>
<artifactId>j2cache-core</artifactId>
<version>2.8.0-release</version>
<!-- 排除 -->
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<finalName>app</finalName>

@ -45,9 +45,10 @@ public class SaticScheduleTask {
@Autowired
private TagDao tagDao;
/*
* @PostConstruct private void init() { updateAutoComplete(); }
*/
@PostConstruct
private void init() {
updateAutoComplete();
}
// 1.凌晨4点执行更新期刊tag
@Scheduled(cron = "0 0 4 * * *")
@ -60,29 +61,28 @@ public class SaticScheduleTask {
}
// 2.凌晨4:20点执行更新分词
/*
* @Scheduled(cron = "0 20 4 * * *") private void updateAutoComplete() {
* Stream<Entry<String, Set<String>>> journalSongStream =
* journalSongDao.findAll().parallelStream() .map(j ->
* getJournalSongMap(j)).flatMap(m -> m.entrySet().stream());
*
* Stream<Entry<String, Set<String>>> journalStream =
* journalDao.findValidJournals().parallelStream() .map(j ->
* getJournalMap(j)).flatMap(m -> m.entrySet().stream());
*
* Map<String, List<Entry<String, Set<String>>>> map =
* Stream.concat(journalSongStream, journalStream)
* .collect(Collectors.groupingBy(e -> e.getKey()));
*
* int keyCount = map.size(); int cacheKeyCount =
* cacheChannel.keys(constants.Constants.J2CACHE_REGION_SEARCH_AUTO_COMPLETE).
* size(); if (keyCount != cacheKeyCount) {
* map.entrySet().parallelStream().forEach(e -> { List<String> value =
* e.getValue().stream().flatMap(a -> a.getValue().stream()).distinct().sorted()
* .collect(Collectors.toList());
* cacheChannel.set(constants.Constants.J2CACHE_REGION_SEARCH_AUTO_COMPLETE,
* e.getKey(), value); }); } }
*/
@Scheduled(cron = "0 20 4 * * *")
private void updateAutoComplete() {
Stream<Entry<String, Set<String>>> journalSongStream = journalSongDao.findAll().parallelStream()
.map(j -> getJournalSongMap(j)).flatMap(m -> m.entrySet().stream());
Stream<Entry<String, Set<String>>> journalStream = journalDao.findValidJournals().parallelStream()
.map(j -> getJournalMap(j)).flatMap(m -> m.entrySet().stream());
Map<String, List<Entry<String, Set<String>>>> map = Stream.concat(journalSongStream, journalStream)
.collect(Collectors.groupingBy(e -> e.getKey()));
int keyCount = map.size();
int cacheKeyCount = cacheChannel.keys(constants.Constants.J2CACHE_REGION_SEARCH_AUTO_COMPLETE).size();
if (keyCount != cacheKeyCount) {
map.entrySet().parallelStream().forEach(e -> {
List<String> value = e.getValue().stream().flatMap(a -> a.getValue().stream()).distinct().sorted()
.collect(Collectors.toList());
cacheChannel.set(constants.Constants.J2CACHE_REGION_SEARCH_AUTO_COMPLETE, e.getKey(), value);
});
}
}
private Map<String, Set<String>> getJournalMap(Journal j) {
Map<String, Set<String>> map = new HashMap<>();

@ -28,10 +28,11 @@ package com.luoo.music.ik.cfg;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.InvalidPropertiesFormatException;
import java.util.List;
import java.util.Properties;
import org.springframework.core.io.ClassPathResource;
/**
* Configuration
* 2012-5-8
@ -42,8 +43,8 @@ public class DefaultConfig implements Configuration{
/*
*
*/
private static final String PATH_DIC_MAIN = "com/luoo/music/ik/dic/main2012.dic";
private static final String PATH_DIC_QUANTIFIER = "com/luoo/music/ik/dic/quantifier.dic";
private static final String PATH_DIC_MAIN = "main2012.dic";
private static final String PATH_DIC_QUANTIFIER = "quantifier.dic";
/*
*
@ -74,16 +75,11 @@ public class DefaultConfig implements Configuration{
private DefaultConfig(){
props = new Properties();
InputStream input = this.getClass().getClassLoader().getResourceAsStream(FILE_NAME);
if(input != null){
try {
props.loadFromXML(input);
} catch (InvalidPropertiesFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
try (InputStream input = new ClassPathResource(FILE_NAME).getInputStream();) {
props.loadFromXML(input);
} catch (IOException e) {
e.printStackTrace();
}
}

@ -32,6 +32,8 @@ import java.io.InputStreamReader;
import java.util.Collection;
import java.util.List;
import org.springframework.core.io.ClassPathResource;
import com.luoo.music.ik.cfg.Configuration;
/**
@ -195,13 +197,8 @@ public class Dictionary {
//建立一个主词典实例
_MainDict = new DictSegment((char)0);
//读取主词典文件
InputStream is = this.getClass().getClassLoader().getResourceAsStream(cfg.getMainDictionary());
if(is == null){
throw new RuntimeException("Main Dictionary not found!!!");
}
try {
BufferedReader br = new BufferedReader(new InputStreamReader(is , "UTF-8"), 512);
try (InputStream is = new ClassPathResource(cfg.getMainDictionary()).getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is , "UTF-8"), 512);) {
String theWord = null;
do {
theWord = br.readLine();
@ -209,21 +206,10 @@ public class Dictionary {
_MainDict.fillSegment(theWord.trim().toLowerCase().toCharArray());
}
} while (theWord != null);
} catch (IOException ioe) {
System.err.println("Main Dictionary loading exception.");
ioe.printStackTrace();
}finally{
try {
if(is != null){
is.close();
is = null;
}
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
System.err.println("Main Dictionary loading exception.");
e.printStackTrace();
}
//加载扩展词典
this.loadExtDict();
}
@ -235,17 +221,11 @@ public class Dictionary {
//加载扩展词典配置
List<String> extDictFiles = cfg.getExtDictionarys();
if(extDictFiles != null){
InputStream is = null;
for(String extDictName : extDictFiles){
//读取扩展词典文件
System.out.println("加载扩展词典:" + extDictName);
is = this.getClass().getClassLoader().getResourceAsStream(extDictName);
//如果找不到扩展的字典,则忽略
if(is == null){
continue;
}
try {
BufferedReader br = new BufferedReader(new InputStreamReader(is , "UTF-8"), 512);
try (InputStream is = new ClassPathResource(extDictName).getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is , "UTF-8"), 512);) {
String theWord = null;
do {
theWord = br.readLine();
@ -255,21 +235,10 @@ public class Dictionary {
_MainDict.fillSegment(theWord.trim().toLowerCase().toCharArray());
}
} while (theWord != null);
} catch (IOException ioe) {
System.err.println("Extension Dictionary loading exception.");
ioe.printStackTrace();
}finally{
try {
if(is != null){
is.close();
is = null;
}
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
System.err.println("Extension Dictionary loading exception.");
e.printStackTrace();
}
}
}
}
@ -283,17 +252,11 @@ public class Dictionary {
//加载扩展停止词典
List<String> extStopWordDictFiles = cfg.getExtStopWordDictionarys();
if(extStopWordDictFiles != null){
InputStream is = null;
for(String extStopWordDictName : extStopWordDictFiles){
System.out.println("加载扩展停止词典:" + extStopWordDictName);
//读取扩展词典文件
is = this.getClass().getClassLoader().getResourceAsStream(extStopWordDictName);
//如果找不到扩展的字典,则忽略
if(is == null){
continue;
}
try {
BufferedReader br = new BufferedReader(new InputStreamReader(is , "UTF-8"), 512);
try (InputStream is = new ClassPathResource(extStopWordDictName).getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is , "UTF-8"), 512);) {
String theWord = null;
do {
theWord = br.readLine();
@ -303,21 +266,10 @@ public class Dictionary {
_StopWordDict.fillSegment(theWord.trim().toLowerCase().toCharArray());
}
} while (theWord != null);
} catch (IOException ioe) {
System.err.println("Extension Stop word Dictionary loading exception.");
ioe.printStackTrace();
}finally{
try {
if(is != null){
is.close();
is = null;
}
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
System.err.println("Extension Stop word Dictionary loading exception.");
e.printStackTrace();
}
}
}
}
@ -329,12 +281,8 @@ public class Dictionary {
//建立一个量词典实例
_QuantifierDict = new DictSegment((char)0);
//读取量词词典文件
InputStream is = this.getClass().getClassLoader().getResourceAsStream(cfg.getQuantifierDicionary());
if(is == null){
throw new RuntimeException("Quantifier Dictionary not found!!!");
}
try {
BufferedReader br = new BufferedReader(new InputStreamReader(is , "UTF-8"), 512);
try (InputStream is = new ClassPathResource(cfg.getQuantifierDicionary()).getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is , "UTF-8"), 512);) {
String theWord = null;
do {
theWord = br.readLine();
@ -342,21 +290,10 @@ public class Dictionary {
_QuantifierDict.fillSegment(theWord.trim().toLowerCase().toCharArray());
}
} while (theWord != null);
} catch (IOException ioe) {
System.err.println("Quantifier Dictionary loading exception.");
ioe.printStackTrace();
}finally{
try {
if(is != null){
is.close();
is = null;
}
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
System.err.println("Quantifier Dictionary loading exception.");
e.printStackTrace();
}
}
}

Loading…
Cancel
Save