线程池不自带结果返回,需要手动需要添加 使用到 Callable Future
public static ExecutorService fixedThreadPool = Executors.newFixedThreadPool(5);
Callable myCallable = new Callable() {
@Override
public Object call() throws Exception {
String fileLink = "http://106.14.117.71/recordings/2020-04-26/2020-04-26-09-50-19-5134_015979792476_999888.wav";
Object response = Rules.AsrRecognition("02188557706", fileLink);
// responseQuery.offer(response);
Thread.sleep(2000);
System.out.println(response);
return response;
}
};
Future future = fixedThreadPool.submit(myCallable);
System.out.println("获取返回值: "+future.get());
@Bean //运行时启动
public void FilesMonitor() throws Exception {
String rootDir = "E:\\javakf";
// 轮询间隔 5 秒
long interval = TimeUnit.SECONDS.toMillis(1);
// 创建过滤器
IOFileFilter directories = FileFilterUtils.and(
FileFilterUtils.directoryFileFilter(),
HiddenFileFilter.VISIBLE);
IOFileFilter files = FileFilterUtils.and(
FileFilterUtils.fileFileFilter(),
FileFilterUtils.suffixFileFilter(".txt"));
IOFileFilter filter = FileFilterUtils.or(directories, files);
// 使用过滤器
FileAlterationObserver observer = new FileAlterationObserver(new File(rootDir), filter);
//不使用过滤器
//FileAlterationObserver observer = new FileAlterationObserver(new File(rootDir));
observer.addListener(new FilesMonitor());
//创建文件变化监听器
FileAlterationMonitor monitor = new FileAlterationMonitor(interval, observer);
// 开始监控
monitor.start();
}