一、初始化

1,直接调用

import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy;

import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
ThreadPoolTaskExecutor poolTaskExecutor = new ThreadPoolTaskExecutor();
//线程池所使用的缓冲队列
poolTaskExecutor.setQueueCapacity(10);
//线程池维护线程的最少数量
poolTaskExecutor.setCorePoolSize(2);
//线程池维护线程的最大数量
poolTaskExecutor.setMaxPoolSize(3);
//线程池维护线程所允许的空闲时间
poolTaskExecutor.setKeepAliveSeconds(300); poolTaskExecutor.setRejectedExecutionHandler(new CallerRunsPolicy());
poolTaskExecutor.initialize(); for (int i = 0; i < 25; i++) {
MessagePrinterTask m=new MessagePrinterTask("Message" + i);
poolTaskExecutor.execute(m);
System.out.println("add Thread:"+i);
} }
}

结果是

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJoAAAI3CAIAAADsgNVZAAARUklEQVR4nO2dTbqqyrJFbRcNoj1Ub2034n7045btxOsBr6Bg/kQm6GItIyZjfKdwFhuT0GkixAC9/fv37/9W/v3795///u8///3fAicyj8tt3P5Ybrdl/q1N3Yjz97kvw225rf9N99/bEnFKQZxSEKcUP4vzPg23sfxcNxfuMI9vP+QdPikpJH8d530abjnDdPcS56u44TePV36Rb83OIj8Pcc7jbV0p7GzeiXMeX9Po9fyyKbYuNhc2seJcN7ZNjXm8jdM2rLGhbYg36uxUtG748biIeR6ena83rPkufvetXcd5q0eax1e26wPSByYJHK2zybbKY6OTMXQA9uJM3/bb092eaPoa1At7tHe2ycONXXD52ZukfaTONo9VtreA9U4JQD/OYgfkIE77ZT5cZ6e4eUzeHVE/PLtx3qdhfYKvveFrYfIRYy7s8Wmc6S5043idOyWlcz1imocPhYZp2l7bbYc3znN/YZuP48z3t9W+dq/Og2dREXe0y0JXSAzilII4pSBOKYhTCuKUAkEmBYLMqC5u8giytIZhuseeyAiyAuk4X6gLsvrxEUGQFSjHe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spring-线程池(3)的更多相关文章

  1. Spring线程池开发实战

    Spring线程池开发实战 作者:chszs,转载需注明. 作者博客主页:http://blog.csdn.net/chszs 本文提供了三个Spring多线程开发的例子,由浅入深,由于例子一目了然, ...

  2. Spring线程池配置模板设计(基于Springboot)

    目录 线程池配置模板 基础的注解解释 常用配置参数 配置类设计 线程池使用 ThreadPoolTaskExecutor源码 线程池配置模板 springboot给我们提供了一个线程池的实现,它的底层 ...

  3. Spring线程池ThreadPoolTaskExecutor配置及详情

    Spring线程池ThreadPoolTaskExecutor配置及详情 1. ThreadPoolTaskExecutor配置 <!-- spring thread pool executor ...

  4. 分享知识-快乐自己:Spring线程池配置

    Spring通过ThreadPoolTaskExecutor实现线程池技术,它是使用jdk中的Java.util.concurrent.ThreadPoolExecutor进行实现. Spring 配 ...

  5. Spring线程池由浅入深的3个示例

    作者博客主页:http://blog.csdn.net/chszs 本文提供了三个Spring多线程开发的例子,由浅入深,由于例子一目了然,所以并未做过多的解释.诸位一看便知. 前提条件: 1)在Ec ...

  6. 【SSM Spring 线程池 OJ】 使用Spring线程池ThreadPoolTaskExecutor

    最近做的Online Judge项目,在本地判题的实现过程中,遇到了一些问题,包括多线程,http通信等等.现在完整记录如下: OJ有一个业务是: 用户在前端敲好代码,按下提交按钮发送一个判题请求给后 ...

  7. spring线程池的同步和异步(1)

    spring线程池(同步.异步) 一.spring异步线程池类图 二.简单介绍 2.1. TaskExecutor---Spring异步线程池的接口类,其实质是java.util.concurrent ...

  8. 007-多线程-JUC线程池-Spring线程池配置、池子如何配置参数

    一.概述 Spring通过ThreadPoolTaskExecutor实现线程池技术,它是使用jdk中的Java.util.concurrent.ThreadPoolExecutor进行实现. 1.1 ...

  9. JDK线程池和Spring线程池的使用

    JDK线程池和Spring线程池实例,异步调用,可以直接使用 (1)JDK线程池的使用,此处采用单例的方式提供,见示例: public class ThreadPoolUtil { private s ...

  10. spring线程池配置

    源自:http://zjriso.iteye.com/blog/771706 1.了解 TaskExecutor接口 Spring的TaskExecutor接口等同于java.util.concurr ...

随机推荐

  1. 使用Docker分分钟启动常用应用

    前言 Docker是目前比较火的一个概念,同时也是微服务中比较关键的一个容器化技术.但是,单从理论上好难看出Docker的优势,因此,我希望在这篇文章中提供一些Docker的使用示例,希望从实际应用上 ...

  2. Omi全新版本来袭 - 指令系统

    写在前面 Omi框架到目前为止有三种版本. omi.js 使用 sodajs 为内置指令系统 omi.lite.js 不包含任何模板引擎 omi.mustache.js 使用 mustache.js为 ...

  3. Linux防火墙配置—访问外网WEB

    一.实验目标 1.本次实验在"Linux基础网络搭建实验"的基础上,在外网虚拟机上搭建WEB服务,并分别配置外网和网关的防火墙规则,使内网能够访问WEB服务 2.Linux基础网络 ...

  4. 什么是Actor

    本文已.Net语法为主,同时写有Scala及Java实现代码 严肃的说,演员是一个广泛的概念,作为外行人我对Actor 模型的定义: Actor是一个系统中参与者的虚拟人物,Actor与Actor之间 ...

  5. Python全栈之路-Day31

    1 反射 反射的精髓是通过字符串去获取对象属性的值 1.1 基于类和对象反射的属性 #!/usr/bin/env python # __Author__: "wanyongzhen" ...

  6. poj1410计算几何线段相交

    You are to write a program that has to decide whether a given line segment intersects a given rectan ...

  7. 转csdn-css4

    http://www.csdn.net/article/2015-03-06/2824127-css4

  8. NancyFx 2.0的开源框架的使用-Basic

    这是NancyFx开源框架中的Basic认证,学习一下! 首先当然是新建一个空的Web,BasicDemo 继续在项目中添加Nuget包,记得安装的Nuget包是最新的预发行版 Nancy Nancy ...

  9. redis之sentinel概述

    一.配置sentinel 修改的是这条: 对应: 上面那条配置需要注意:<master-name>:监控主节点的名称 <ip>:监控主节点的ip   <redis-por ...

  10. BM25和Lucene Default Similarity比较 (原文标题:BM25 vs Lucene Default Similarity)

    原文链接: https://www.elastic.co/blog/found-bm-vs-lucene-default-similarity 原文 By Konrad Beiske 翻译 By 高家 ...