JDK1.5中的线程池使用简介(无名)

RT-Thread 入门学习笔记 - 创建无法删除的线程 前言 学习了RT-Thread的内核组件与线程管理,我忽然发现,线程创建时,名字可以使用RT_NULL。 创建无名线程,工作正常,只是,无法删除 相关代码 #include <rtthread.h> #define DBG_SECTION_NAME "noname" #define DBG_LEVEL DBG_LOG #include <rtdbg.h> /* led test */ extern void led_red_on(void. 阅读详情

在多线程大师Doug Lea的贡献下,在JDK1.5中加入了许多对并发特性的支持,例如:线程池。

一、简介
线程池类为 java.util.concurrent.ThreadPoolExecutor,常用构造方法为:
              
    ThreadPoolExecutor(int corePoolSize, int maximumPoolSize,
                long keepAliveTime, TimeUnit unit,
                BlockingQueue workQueue,
                RejectedExecutionHandler handler)
               

    corePoolSize:   线程池维护线程的最少数量
    maximumPoolSize:线程池维护线程的最大数量
    keepAliveTime:  线程池维护线程所允许的空闲时间
    unit:           线程池维护线程所允许的空闲时间的单位
    workQueue:      线程池所使用的缓冲队列
    handler:        线程池对拒绝任务的处理策略
   
    一个任务通过 execute(Runnable)方法被添加到线程池,任务就是一个 Runnable类型的对象,任务的执行方法就是 Runnable类型对象的run()方法。
   
    当一个任务通过execute(Runnable)方法欲添加到线程池时:
   
    如果此时线程池中的数量小于corePoolSize,即使线程池中的线程都处于空闲状态,也要创建新的线程来处理被添加的任务。

    如果此时线程池中的数量等于 corePoolSize,但是缓冲队列 workQueue未满,那么任务被放入缓冲队列。

    如果此时线程池中的数量大于corePoolSize,缓冲队列workQueue满,并且线程池中的数量小于maximumPoolSize,建新的线程来处理被添加的任务。

    如果此时线程池中的数量大于corePoolSize,缓冲队列workQueue满,并且线程池中的数量等于maximumPoolSize,那么通过 handler所指定的策略来处理此任务。
   
    也就是:处理任务的优先级为:
    核心线程corePoolSize、任务队列workQueue、最大线程maximumPoolSize,如果三者都满了,使用handler处理被拒绝的任务。
   
    当线程池中的线程数量大于 corePoolSize时,如果某线程空闲时间超过keepAliveTime,线程将被终止。这样,线程池可以动态的调整池中的线程数。
   
    unit可选的参数为java.util.concurrent.TimeUnit中的几个静态属性:
    NANOSECONDS、MICROSECONDS、MILLISECONDS、SECONDS。
   
    workQueue我常用的是:java.util.concurrent.ArrayBlockingQueue
   
    handler有四个选择:
    ThreadPoolExecutor.AbortPolicy()       
       抛出java.util.concurrent.RejectedExecutionException异常
    ThreadPoolExecutor.CallerRunsPolicy()  
       重试添加当前的任务,他会自动重复调用execute()方法
    ThreadPoolExecutor.DiscardOldestPolicy()
       抛弃旧的任务
    ThreadPoolExecutor.DiscardPolicy()     
       抛弃当前的任务

   
二、一般用法举例
//------------------------------------------------------------
//TestThreadPool.java
//package cn.simplelife.exercise;

import java.io.Serializable;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class TestThreadPool {

    private static int produceTaskSleepTime = 2;
    private static int consumeTaskSleepTime = 2000;
    private static int produceTaskMaxNumber = 10;
   
public static void main(String[] args) {

        //构造一个线程池   
        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(2, 4, 3,
                TimeUnit.SECONDS, new ArrayBlockingQueue(3),
                new ThreadPoolExecutor.DiscardOldestPolicy());

        for(int i=1;i<=produceTaskMaxNumber;i++){
            try {              
                //产生一个任务,并将其加入到线程池
                String task = "task@ " + i;
    System.out.println("put " + task);
    threadPool.execute(new ThreadPoolTask(task));
   
    //便于观察,等待一段时间
                Thread.sleep(produceTaskSleepTime);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
}

/**
  * 线程池执行的任务
  * @author hdpan
  */
    public static class ThreadPoolTask implements Runnable,Serializable{
     private static final long serialVersionUID = 0;
     //保存任务所需要的数据
        private Object threadPoolTaskData;
       
        ThreadPoolTask(Object tasks){
            this.threadPoolTaskData = tasks;
        }
        public void run(){
            //处理一个任务,这里的处理方式太简单了,仅仅是一个打印语句
   System.out.println("start .."+threadPoolTaskData);
         try {
             ////便于观察,等待一段时间
                Thread.sleep(consumeTaskSleepTime);
            } catch (Exception e) {
                e.printStackTrace();
            }
            threadPoolTaskData = null;
        }
        public Object getTask(){
            return this.threadPoolTaskData;
        }
    }
}
//------------------------------------------------------------
说明:
1、在这段程序中,一个任务就是一个Runnable类型的对象,也就是一个ThreadPoolTask类型的对象。

2、一般来说任务除了处理方式外,还需要处理的数据,处理的数据通过构造方法传给任务。

3、在这段程序中,main()方法相当于一个残忍的领导,他派发出许多任务,丢给一个叫 threadPool的任劳任怨的小组来做。

    这个小组里面队员至少有两个,如果他们两个忙不过来, 任务就被放到任务列表里面。

    如果积压的任务过多,多到任务列表都装不下(超过3个)的时候,就雇佣新的队员来帮忙。但是基于成本的考虑,不能雇佣太多的队员, 至多只能雇佣 4个。

    如果四个队员都在忙时,再有新的任务, 这个小组就处理不了了,任务就会被通过一种策略来处理,我们的处理方式是不停的派发, 直到接受这个任务为止(更残忍!呵呵)。

    因为队员工作是需要成本的,如果工作很闲,闲到 3SECONDS都没有新的任务了,那么有的队员就会被解雇了,但是,为了小组的正常运转,即使工作再闲,小组的队员也不能少于两个。

4、通过调整 produceTaskSleepTime和 consumeTaskSleepTime的大小来实现对派发任务和处理任务的速度的控制, 改变这两个值就可以观察不同速率下程序的工作情况。

5、通过调整4中所指的数据,再加上调整任务丢弃策略, 换上其他三种策略,就可以看出不同策略下的不同处理方式。

6、对于其他的使用方法,参看jdk的帮助,很容易理解和使用。

 

jdk1.5 线程并发与线程池的使用 整理的一些资料,jdk1.5新增加对线程并发的处理类,可以学习一下 立即下载

相关推荐

JDK1.5中的线程池(java.util.concurrent.ThreadPoolExecutor)使用

JDK1.5中的线程池(java.util.concurrent.ThreadPoolExecutor)使用

创建线程三种方法

null :池中一直保持的线程的数量,即使线程空闲也不会释放。除非设置了 allowCoreThreadTimeOut *池中允许的最大的线程数当线程数大于核心线程数的时候,线程在最大多长时间没有接到新任务就会终止释放, 最终线程池维持在 corePoolSize 大小时间单位阻塞队列,用来存储等待执行的任务,如果当前对线程的需求超过了 corePoolSize大小,就会放在这里等待空闲线程执行。创建线程的工厂,比如指定线程名等。

一个菜鸡的博客 5958

图像超分辨率在医学影像中的应用:如何用深度学习提升CT/MRI图像质量

本文探讨了深度学习驱动的图像超分辨率技术在医学影像(如CT/MRI)质量提升中的应用。文章分析了医学图像超分辨率在提升诊断信息含量、平衡保真度与临床相关性方面的独特挑战,并详细介绍了如何针对3D体数据特点定制模型架构、设计病理感知损失函数,以及解决高质量配对数据稀缺的策略。通过实战案例,阐述了从数据模拟、模型训练到临床评估的完整流程,旨在为医学影像的清晰化与诊断精准化提供有效解决方案。

weixin_29063681的博客 525

JDK1.5中的线程池(java.util.concurrent.ThreadPoolExecutor)使用简介

JDK1.5中的线程池(java.util.concurrent.ThreadPoolExecutor)使用简介

robage的专栏 2万+

编译原理2024期末复习(面向做题,大题速学)【太原理工大学】

归约-归约”冲突就是在项目集规范族一个状态中两个。

m0_63181421的博客 1万+

什么是三极管推挽电路

当没有信号输入时,电源通过PNP三极管EB间的二极管,然后通过NPN三极管BE间而二极管到地,这时这两个三极管都是导通的,三极管很容易由于电流过大而损坏。当输入信号为VCC时,上面的三极管导通,下面的三极管截止,输出信号为VCC-0.7V,这个0.7V就是上面NPN三极管BE间的导通压降。比如上面的三极管导通,那么输出电压就是输入电压减去0.7V,所以下面的PNP三极管由于基极电压大于发射极电压,是不会导通的。这是一个三极管推挽电路,上面是一个NPN的三极管,下面是一个PNP的三极管。

谢谢关注“小鱼教你模数电”,各平台同号 3374

timestasks java_JDK1.5中的线程池使用简介(无名)

在多线程大师Doug Lea的贡献下,在JDK1.5中加入了许多对并发特性的支持,例如:线程池。一、简介线程池类为 java.util.concurrent.ThreadPoolExecutor,常用构造方法为:ThreadPoolExecutor(int corePoolSize, int maximumPoolSize,long keepAliveTime, TimeUnit unit,Blo...

weixin_29825411的博客 94

使用ChIPSeeker进行ChIP-seq, ATAC-seq,cut&tag等富集峰的基因组注释

常规的下一代高通量测序(next generation sequencing, NGS)实验通常产生大量短片段(reads),通常我们需要将这些reads比对到参考基因组/转录组上,即将它们置于生物学上有意义的基因背景下,才能获得有意义的结果。一般我们认为会产生两种类型的数据(当然两者并无严格意义上的区分)

微生信 3320

JDK1.5中的线程池

JDK1.5中的线程池(java.util.concurrent.ThreadPoolExecutor)使用简介收藏 在多线程大师Doug Lea的贡献下,在JDK1.5中加入了许多对并发特性的支持,例如:线程池。 一、简介 线程池类为 java.util.concurrent.ThreadPoolExecutor,常用构造方法为: ThreadPoolExecutor(int...

iteye_13083的博客 577

PCIe 6.0 – 关于 PCI Express Gen6 您需要知道的一切

幸运的是,PCIe 6.0 FEC 足够轻,对延迟的影响最小。在电气层上,PCIe 6.0 使用 PAM4 信号(“四级脉冲幅度调制”),每个时钟周期将 2 位组合为 4 个幅度级别(00、01、10、11),与 PCIe 5.0 和前几代相比,它使用 NRZ 调制,每个时钟周期 1 位和两个幅度级别 (0, 1)。虽然 PAM4 信号更容易出错,但由于调制技术的性质,与 PCIe 5.0 相比,通道损耗不受影响,因此 PCB 上 PCIe 6.0 信号的范围将与 PCIe 5.0 相同。

qq_43416206的博客 3433

我在腾讯上构建了一个人人能用的机载适航知识库

当ChatGPT掀起生成式AI的浪潮时,工程师们发现了一个尴尬的现实:询问“如何编写软件合格审定计划”,AI的回答可能充满似是而非的术语,却无法精确关联FDO-178C的对应内容。现在市面上有许多的AI大模型+适航知识库的方案,之前我的文章介绍了一种本地大模型加知识库的解决方法。此外,ima知识库的容量大小可以到30GB(企鹅大气),只要管理好文件的格式,理论上是完全可以把机载适航相关的内容容纳进去的。后续会不断增加适航法规,适航规章,适航标准,适航书籍,适航相关的论文,以及网上其他一些优秀的内容。

qq_41854911的博客 1227

JDK1.8 创建线程池有哪几种方式?

JDK1.8创建线程池有哪几种方式? newFixedThreadPool 定长线程池,每当提交一个任务就创建一个线程,直到达到线程池的最大数量,这时线程数量不再变化,当线程发生错误结束时,线程池会补充一个新的线程 测试代码: public class TestThreadPool { //定长线程池,每当提交一个任务就创建一个线程,直到达到线程池的最大数量,这时线程数量不再变化...

ConstXiong 2万+

YOLO11检测中的内存占用分析与优化:讲解如何分析并优化推理时的内存使用

YOLOv11模型内存分析与优化摘要:本文系统分析了YOLOv11目标检测模型的内存使用模式,重点探讨了显存(VRAM)、系统内存(RAM)和共享内存的特性差异。通过PyTorch内置工具和自定义分析器,详细剖析了骨干网络、颈部网络和检测头各组件内存占用规律,指出激活值内存与输入尺寸呈平方级增长关系。文章提供了卷积层内存计算公式,并强调合理规划"工作台"(显存)与"仓库"(内存)间的数据流动是优化关键。最后通过流程图直观展示了YOLOv11推理过程的三类内存使用模式,

本博客聚焦 YOLOv11 全流程落地,涵盖架构优化、数据集处理、训练技巧与多场景部署,兼及国产数据库、Java 开发与 AI 模型应用,内容兼顾理论与工程实践,为开发者提供系统干货,助力高效提升技术能力。 346

JAVA JDK1.5 线程池

在多线程并发的条件下,由于系统资源有限,需要限制同时执行的线程的数量,JDK1.5提供了线程池来控制多线程的执行。 JDK1.5中的线程池包含以下三种: 1.newSingleThreadExecutor:创建一个单线程的线程池,这个线程池最多只有一个线程在执行,也就是相当于单线程串行执行 2.newFixedThreadPool:创建固定大小的线程池。每次提交一个任务就创建一个线程,直到线

brushli的专栏 1171

dolphinscheduler服务注册中心源码解析(一)服务注册与发现整体设计

下一篇文章我们开始讲解dolphinscheduler基于Zookeeper实现注册中心的源码解析。

最爱嫣夜来 376

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

JDK1.5中的线程池使用简介

学习 JDK1.5中的线程池使用简介 在多线程大师Doug Lea的贡献下,在JDK1.5中加入了许多对并发特性的支持,例如:线程池。这里介绍的就是1.5种的线程池的简单使用方法。创建日期:2005-05-11最后修改日期:2007-03-06panhaidong@gmail.com 一、简介 线程池类为 java.util.concurrent.ThreadP...

dalezhu的专栏 201

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

JDK1.8 并发之线程池

线程池 优点: 1. 重用线程池中的线程,避免线程的创建销毁带来的性能开销。 2. 控制线程池的最大并发数。 3. 对线程简单管理:如定时执行以及指定间隔循环执行。 实现 ThreadPoolExecutor方法是线程池的真正实现,下面是它的一个比较常用的构造方法: public ThreadPoolExecutor(int corePoolSize, ...

哈罗德Android笔记 3978

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

就是java的线程池是吧_java线程池  JDK1.5(一)

JDK5中的一个亮点就是将Doug Lea的并发库引入到Java标准库中。DougLea确实是一个牛人,能教书,能出书,能编码,不过这在国外还是比较普遍的,而国内的教授们就相差太远了。一般的服务器都需要线程池,比如Web、FTP等服务器,不过它们一般都自己实现了线程池,比如以前介绍过的Tomcat、Resin和Jetty等,现在有了JDK5,我们就没有必要重复造车轮了,直接使用就可以,何况使用也很...

weixin_32148341的博客 131

JDK1.5中的线程池(java.util.concurrent.ThreadPoolExecut

JDK1.5中的线程池(java.util.concurrent.ThreadPoolExecut 9推荐在多线程大师Doug Lea的贡献下,在JDK1.5中加入了许多对并发特性的支持,例如:线程池。<br /><br />一、简介<br />线程池类为 java.util.concurrent.ThreadPoolExecutor,常用构造方法为:<br /><br />ThreadPoolExecutor(int corePoolSize, int maximumPoolSize,<br />long

yuanxuegui2008的专栏 527

JDK1.5中的线程池(java.util.concurrent.ThreadPoolExecutor)使用简介 (转)

转自 : http://blog.csdn.net/robage/article/details/1620691在多线程大师Doug Lea的贡献下,在JDK1.5中加入了许多对并发特性的支持,例如:线程池。一、简介线程池类为 java.util.concurrent.ThreadPoolExecutor,常用构造方法为:ThreadPoolExecutor(int corePoolSize, i

Edison Xu 639

ThreadPoolExecutor jdk1.5中的线程池使用简介

一、简介     线程池类为 java.util.concurrent.ThreadPoolExecutor,常用构造方法为: ThreadPoolExecutor(int corePoolSize, int maximumPoolSize,long keepAliveTime, TimeUnit unit,BlockingQueue workQueue,RejectedExecutionH...

iteye_5095的博客 135

Java线程池详解(为什么要有线程池、线程池的继承关系、线程池的底层原理、手工创建线程池、JDK内置的4大线程池)

文章目录1.为什么有线程池的出现?2. 线程池的继承关系3. 线程池的底层原理4.线程池的创建与使用4.1 手工创建线程池4.2 向线程池提交任务4.2.1 execute()方法4.2.2 submit()方法5.JDK内置的4大线程池5.1 普通调度池5.1.1 无大小限制的线程池5.1.2 固定大小的线程池5.1.3 单线线程5.2 定时调度池5.2.1 Executors.new...

zhao_miao的博客 3320

jdk1.5——使用Executors创建线程池

      利用jdk提供线程池执行任务写法, 主要是查看 API文档的 Executors 方法   package thread; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit...

后知后觉的it路 249

5 线程池的使用

在 Java 中,我们可以利用多线程来最大化地压榨 CPU 多核计算的能力。但是,线程本身是把双刃剑,我们需要知道它的利弊,才能在实际系统中游刃有余地运用。在进入主题之前,我们先了解一下线程池的基本概念。线程池,本质上是一种对象池,用于管理线程资源。在任务执行前,需要从线程池中拿出线程来执行。在任务执行完成之后,需要把线程放回线程池。通过线程的这种反复利用机制,可以有效地避免直接创建线程所带来的坏处。我们先来看看线程池带来了哪些好处。降低资源的消耗。

qq_24907431的博客 1466
上一篇: svchost.exe 上传下载占用大量资源
下一篇: oracle优化(自网络)
wuycjava
博客等级 码龄15年 1粉丝 2原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值