• java 线程池 newFixedThreadPool 返回


    线程池不自带结果返回,需要手动需要添加  使用到 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();
    }
  • 相关阅读:
    ant design pro梳理
    JSON.stringify()
    数组小细节
    js this细节
    策略模式解决if-else过多
    使用useState的赋值函数异步更新问题
    Hook
    React Api
    Intent
    树的非递归遍历
  • 原文地址:https://www.cnblogs.com/MyIsLu/p/13495517.html
Copyright © 2020-2023  润新知