|
|
@ -9,9 +9,11 @@ import org.springframework.core.io.Resource;
|
|
|
|
import org.springframework.core.io.ResourceLoader;
|
|
|
|
import org.springframework.core.io.ResourceLoader;
|
|
|
|
import org.springframework.core.task.TaskExecutor;
|
|
|
|
import org.springframework.core.task.TaskExecutor;
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
|
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
|
|
|
|
import javax.annotation.PreDestroy;
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
@ -67,6 +69,11 @@ public class SensitiveWordsConfig {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private ResourceLoader resourceLoader;
|
|
|
|
private ResourceLoader resourceLoader;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 是否终止线程
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private volatile boolean stop = false;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 初始化敏感词字典
|
|
|
|
* 初始化敏感词字典
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -120,7 +127,7 @@ public class SensitiveWordsConfig {
|
|
|
|
* 实现热更新,修改词典后自动加载
|
|
|
|
* 实现热更新,修改词典后自动加载
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private void startScheduledUpdate() {
|
|
|
|
private void startScheduledUpdate() {
|
|
|
|
while (true) {
|
|
|
|
while (!stop) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
TimeUnit.SECONDS.sleep(UPDATE_TIME_SECONDS);
|
|
|
|
TimeUnit.SECONDS.sleep(UPDATE_TIME_SECONDS);
|
|
|
|
log.debug("SensitiveWordConfig#startScheduledUpdate start update...");
|
|
|
|
log.debug("SensitiveWordConfig#startScheduledUpdate start update...");
|
|
|
@ -128,9 +135,22 @@ public class SensitiveWordsConfig {
|
|
|
|
storeSensWords();
|
|
|
|
storeSensWords();
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
log.error("SensitiveWordConfig#startScheduledUpdate interrupted: {}", e.getMessage());
|
|
|
|
log.error("SensitiveWordConfig#startScheduledUpdate interrupted: {}", e.getMessage());
|
|
|
|
|
|
|
|
Thread.currentThread().interrupt();
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* onDestroy
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@PreDestroy
|
|
|
|
|
|
|
|
public void onDestroy() {
|
|
|
|
|
|
|
|
stop = true;
|
|
|
|
|
|
|
|
if (taskExecutor instanceof ThreadPoolTaskExecutor) {
|
|
|
|
|
|
|
|
ThreadPoolTaskExecutor threadPoolTaskExecutor = (ThreadPoolTaskExecutor) taskExecutor;
|
|
|
|
|
|
|
|
threadPoolTaskExecutor.shutdown();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|