zoukankan      html  css  js  c++  java
  • 多线程之定长线程

    public static void main(String[] args) throws ExecutionException, InterruptedException {
            ExecutorService executor = Executors.newFixedThreadPool(10);
            ExecutorCompletionService<String> service = new ExecutorCompletionService(executor);
            List<Future<String>> result = new ArrayList<Future<String>>();
            for (int i = 0; i < 100; i++) {
                result.add( service.submit(() -> {
                    return gety();
                }));
            }
            for (Future<String> f : result) {
                System.out.println(f.get());
            }
            executor.shutdown();
        }
    
    
    
        public static String  gety() throws InterruptedException {
            System.out.println("开始执行");
            Thread.sleep(2000l);
            System.out.println("结束执行");
            return "ok";
        }
  • 相关阅读:
    BZOJ 1003 物流运输
    549565
    26566
    68
    554554
    5656
    49886
    5989
    6898
    656
  • 原文地址:https://www.cnblogs.com/yy123/p/10935293.html
Copyright © 2011-2022 走看看