博客
关于我
线程的创建方式(四)
阅读量:274 次
发布时间:2019-03-01

本文共 860 字,大约阅读时间需要 2 分钟。

多线程的创建方式(四)

在这里插入图片描述

在这里插入图片描述

  • 提供指定数量的线程池
  • 执行指定的线程操作,需要提供实现runnable接口或callable接口实现类的对象
  • 关闭连接池
package com.ran;import java.util.concurrent.*;import java.util.concurrent.locks.ReentrantLock;public class ran {       public static void main(String[] args) {           ExecutorService service = Executors.newFixedThreadPool(10);        ThreadPoolExecutor service1= (ThreadPoolExecutor) service;                //线程池的属性设置        service1.setCorePoolSize(15);        service1.setKeepAliveTime();        service.execute(new duoxiancheng()); //适合适用于Runnable        service.shutdown();//        service.submit(); //适合适用于Callable    }}class duoxiancheng implements Runnable{       @Override    public void run() {           for (int i = 0; i <=100 ; i++) {               if(i % 2 == 0){                   System.out.println(Thread.currentThread().getName()+" "+i);            }        }    }}

转载地址:http://mkox.baihongyu.com/

你可能感兴趣的文章
MySQL函数
查看>>
mysql函数汇总之字符串函数
查看>>
mysql函数汇总之数学函数
查看>>
mysql函数汇总之日期和时间函数
查看>>
mysql函数汇总之条件判断函数
查看>>
mysql函数汇总之系统信息函数
查看>>
MySQL函数简介
查看>>
mysql函数遍历json数组
查看>>
MySQL函数(转发)
查看>>
mysql分区表
查看>>
MySQL分层架构与运行机制详解
查看>>
mysql分库分表中间件简书_MySQL分库分表
查看>>
MySQL分库分表会带来哪些问题?分库分表问题
查看>>
MySQL分组函数
查看>>
MySQL分组查询
查看>>
Mysql分表后同结构不同名称表之间复制数据以及Update语句只更新日期加减不更改时间
查看>>
mySql分页Iimit优化
查看>>
MySQL分页查询
查看>>
WebDriverException:未知错误:对于旧版本的 Google Chrome,在 Python 中找不到带有 Selenium 的 Chrome 二进制错误
查看>>
mysql列转行函数是什么
查看>>