zoukankan      html  css  js  c++  java
  • 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();
    }
  • 相关阅读:
    解决浏览器跨域限制方案之WebSocket
    解决浏览器跨域限制方案之CORS
    解决浏览器跨域限制方案之JSONP
    浏览器跨域限制概述
    tomcat cluster配置实战注意事项
    学习go语言编程系列之定义变量
    修改xshell的默认字间距和行间距
    学习go语言编程系列之helloworld
    hive操作语句使用详解
    Hive通过查询语句向表中插入数据注意事项
  • 原文地址:https://www.cnblogs.com/MyIsLu/p/13495517.html
Copyright © 2011-2022 走看看