zoukankan      html  css  js  c++  java
  • 线程池的使用方法

    线程池

    主要是为了提升性能,线程重复利用。每个线程都创建十分消耗性能。线程池就像共享单车。

    package Thread;
    
    import java.util.concurrent.Executor;
    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Executors;
    
    public class TestThreadPool {
        public static void main(String[] args) {
            ExecutorService service = Executors.newFixedThreadPool (10);//第一步
            service.execute (new MyThread ());//第二部
            service.execute (new MyThread ());
            service.execute (new MyThread ());
            service.execute (new MyThread ());
            service.submit (new MyThread ());//有返回值,但是我也不知道怎么用?
            service.shutdown ();//关闭线程池
        }
    }
    class MyThread implements Runnable{
        @Override
        public void run() {
            System.out.println (Thread.currentThread ().getName ());
        }
    }
    
  • 相关阅读:
    Python 函数 之 目录
    python---------匿名函数
    python-------递归函数
    python-----内置函数
    hibernate.cfg.xml
    struts2 工作原理
    拦截器
    js制作 子菜单
    struts---最简单实例步骤
    常用标签---地址----
  • 原文地址:https://www.cnblogs.com/li33/p/12722802.html
Copyright © 2011-2022 走看看