一、初始化

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. &lt;转&gt;简单之美——系统设计黄金法则

    作者: 包云岗  发布时间: 2012-05-19 13:06  阅读: 3036 次  推荐: 1   原文链接   [收藏] 最近多次看到系统设计与实现的文章与讨论,再加上以前读过的其他资料以及自 ...

  2. priority_queue 优先队列用法

    //采用默认优先关系: //(priority_queue<int>que;) //Queue 0: // 91 83 72 56 47 36 22 14 10 7 3 // //采用结构 ...

  3. Oracle数据库作业-4 查询

    9. 查询"95031"班的学生人数.

  4. Python partial函数

    以前都是摘录的其他网友的博客,很少是自己写的,学习阶段,多多学习.今天开始自己写了,首先写一下刚刚遇到的partial函数. 1.partial函数主要是对参数的改变,假如一个函数有两个参数,而其中一 ...

  5. javascript数组去重算法-----4

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. hive自定义UDF

    udf udaf udtf 使用方式 hiverc文件 1.jar包放到安装日录下或者指定目录下 2.${HIVE_HOME}/bin目录下有个.hiverc文件,它是隐藏文件. 3.把初始化语句加载 ...

  7. Unity修改Particles Render Material(Unity3D开发之二十三)

    猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blog.csdn.net/cocos2der/article/details/48372999 ...

  8. python基础学习之文件操作&amp;函数

    1.文件处理相关 1.编码问题 ①python2与python3中的默认编码: py2默认使用ASCII码,py3默认使用utf-8 ②为什么会出现中文乱码,中文乱码的情况有哪些? #sys.stdo ...

  9. CSS遮罩效果和毛玻璃效果

    前面的话 本文将详细介绍CSS遮罩效果和毛玻璃效果 遮罩效果 普通遮罩 一般地,处理全屏遮罩的方法是使用额外标签 <style>.overlay{ position:fixed; top: ...

  10. WebApi路由解析增加版本控制

    1.自定义路由解析类 public class VersionHttpControllerSelector : IHttpControllerSelector { private const stri ...