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

    线程池在系统启动时即创建大量空闲的线程,程序将一个Runnable对象传给线程池,线程池就会启动一天线程来执行该对象的run方法 ,放run方法执行结束后,该线程并不会死亡,而是返回线程池中成为空闲状态,等待执行下一个Runnable对象的run方法

    还可以控制系统中并发的线程数量

     1 package com.thread;
     2 
     3 import java.util.concurrent.ExecutorService;
     4 import java.util.concurrent.Executors;
     5 
     6 public class ThreadPoolTest {
     7     public static void main(String[] args) {
     8         ExecutorService poolExecutorService=Executors.newFixedThreadPool(6);
     9         poolExecutorService.submit(new TestThread());
    10         poolExecutorService.submit(new TestThread());
    11         poolExecutorService.shutdown();
    12     }
    13 }
    14 
    15 class TestThread implements Runnable {
    16     public void run() {
    17         for (int i = 0; i < 10; i++) {
    18             System.out.println(Thread.currentThread().getName() + i);
    19         }
    20     }
    21 }
    View Code
  • 相关阅读:
    hdu4059 The Boss on Mars
    cf475D CGCDSSQ
    HDU
    cf1447D Catching Cheaters
    cf1440 Greedy Shopping
    Treats for the Cows
    dp废物学会了记录路径
    D. Jzzhu and Cities
    cf1359D Yet Another Yet Another Task
    关于sg函数打表的理解
  • 原文地址:https://www.cnblogs.com/liutoutou/p/3328740.html
Copyright © 2011-2022 走看看