1.fix schedule task issue

main
Gary 11 months ago
parent b792b647f5
commit c90deee5c6

@ -21,10 +21,6 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency> <dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
@ -89,10 +85,12 @@
<artifactId>j2cache-spring-boot2-starter</artifactId> <artifactId>j2cache-spring-boot2-starter</artifactId>
<version>2.8.0-release</version> <version>2.8.0-release</version>
</dependency> </dependency>
<!-- j2cache依赖 -->
<dependency> <dependency>
<groupId>net.oschina.j2cache</groupId> <groupId>net.oschina.j2cache</groupId>
<artifactId>j2cache-core</artifactId> <artifactId>j2cache-core</artifactId>
<version>2.8.5-release</version> <version>2.8.0-release</version>
<!-- 排除 -->
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>

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

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

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

Loading…
Cancel
Save