zoukankan      html  css  js  c++  java
  • 线程池

    1.线程池的概念及作用线程池,其实就是一个容纳多个线程的容器,

    其中的线程可以反复使用,省去了频繁创建线程对象的操作,无需反复创建线程而消耗过多资源。

    2.线程池的使用方法

    public static void main(String[] args) throws InterruptedException, ExecutionException {
            //创建线程任务
            MyCallable mc = new MyCallable();
            //创建线程对象
            ExecutorService es = Executors.newFixedThreadPool(2);
            //执行线程任务
            Future <String> f = es.submit(mc);
            //获取返回值
            String str= f.get();    
            System.out.println(str);        
        }
    public class MyCallable implements Callable<String> {
    
        public String call() throws Exception {    
            
            return "呵呵";
            
        }

    注意 : 这里实现线程任务接口改用Callable<T> ,他可以返回一个指定泛型的返回值

  • 相关阅读:
    MongoDB的简单操作
    MongoDB下载安装
    enctype="multipart/form-data" form表单提交值为null
    shiro
    json简单介绍
    Sql Server 安装
    MySQL面试常问的查询操作
    关于分页
    Vuex
    Vue基础安装(精华)
  • 原文地址:https://www.cnblogs.com/lxzwhite/p/10553282.html
Copyright © 2011-2022 走看看