多线程学习(2):ScheduledThreadPoolExecutor 与 schedule 之小结

Java线程池 线程池使 java中经常需要用到多线程来处理一些业务,我们非常不建议单纯使用继承Thread或者实现Runnable接口的方式来创建线程,那样势必有创建及销毁线程耗费资源、线程上下文切换问题。同时创建过多的线程也可能引发资源耗尽的风险,这个时候引入线程池比较合理,方便线程任务的管理。java中涉及到线程池的相关类均在jdk1.5开始的java.util.concurrent包中, 涉及到的几个核心类及接口包括: Executor、 Executors、 ExecutorService、 Thre 阅读详情

2018年7月9日08:48:58

欢迎扫二维码关注公众号,获取技术干货

【1】前言

    线程池与任务定时执行,一是项目随处可见的一种技术,二是自己还需打打扎实基础;不可以仅仅局限于业务的实现,要去体会底层的思想;

 

【2】关于线程池ThreadPoor与Timer的使用

 

2.1    Java提供的Time类可以周期性地或者延期执行任务,但是有时我们需要并行执行同样的任务,这个时候如果创建多个Time对象会给系统带来负担,解决办法是将定时任务放到线程池中执行。

    Java的ScheduledThreadPoolExecutor类实现了ScheduledExecutorService接口中定义的以不同方法执行任务的方法。

2.2 ScheduleThreadPoolExecutor与Timer相比的优势

 

(1)Timer是基于绝对时间的延时执行或周期执行,当系统时间改变,则任务的执行会受到的影响。而ScheduleThreadPoolExecutore中,任务时基于相对时间进行周期或延时操作。

(2)Timer也可以提交多个TimeTask任务,但只有一个线程来执行所有的TimeTask,这样并发性受到影响。而ScheduleThreadPoolExecutore可以设定池中线程的数量。

(3)Timer不会捕获TimerTask的异常,只是简单地停止,这样势必会影响其他TimeTask的执行。而ScheduleThreadPoolExecutore中,如果一个线程因某些原因停止,线程池可以自动创建新的线程来维护池中线程的数量。

 

2.3 自jdk1.5开始,Java开始提供ScheduledThreadPoolExecutor类来支持周期性任务的调度,在这之前,这些工作需要依靠Timer/TimerTask或者其它第三方工具来完成。但Timer有着不少缺陷,如Timer是单线程模式,调度多个周期性任务时,如果某个任务耗时较久就会影响其它任务的调度;如果某个任务出现异常而没有被catch则可能导致唯一的线程死掉而所有任务都不会再被调度。ScheduledThreadPoolExecutor解决了很多Timer存在的缺陷。JDK1.5之前的Timer和TimerTask类已经过时了。

通过如上的介绍,可以对比一下Timer和ScheduledThreadPoolExecutor:

TimerScheduledThreadPoolExecutor
单线程多线程
单个任务执行时间影响其他任务调度多线程,不会影响
基于绝对时间基于相对时间
一旦执行任务出现异常不会捕获,其他任务得不到执行多线程,单个任务的执行不会影响其他线程

所以,在JDK1.5之后,应该没什么理由继续使用Timer进行任务调度了。


【3】ScheduledThreadPoolExecutor 工作原理

 

【4】源码

 

【5】实现例子

BusinessPool.java:

package test2;

import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class BusinessPool {
	
	 private ScheduledThreadPoolExecutor executor;
	    
	    BusinessPool() {
	    }
		
		public static class BusinessPoolThreadFactory implements ThreadFactory {
			final ThreadGroup group = Thread.currentThread().getThreadGroup();
	        final AtomicInteger threadNumber = new AtomicInteger(1);
	        final String namePrefix = "business-pool";
	        
	        @Override
	        public Thread newThread(Runnable r) {
	            Thread t = new Thread(group, r,
	                                  namePrefix + threadNumber.getAndIncrement(),
	                                  0);
	            if (t.isDaemon())
	                t.setDaemon(false);
	            if (t.getPriority() != Thread.NORM_PRIORITY)
	                t.setPriority(Thread.NORM_PRIORITY);
	            return t;
	        }
		}
		
	    public void init() {
	    	this.executor = new ScheduledThreadPoolExecutor(1, new BusinessPoolThreadFactory());
	    }
	 
	    
	    public void schedule(Runnable runnable, long delay, TimeUnit unit) {
	        executor.schedule(runnable, delay, unit);
	    }
	    
	    public void execute(Runnable runnable) {
	        executor.execute(runnable);
	    }
	    
	    
}

 

test.java:

package test2;

import java.util.concurrent.TimeUnit;

public class test23 {

	public static void main(String[] args) {
		BusinessPool businessPool = new BusinessPool();
		businessPool.init();
		businessPool.schedule(new Runnable() {
			@Override
			public void run() {
				System.out.println("Hello world 0_0|||");
			}
		}, 3, TimeUnit.SECONDS);
	}

}

输出结果(延时3s执行线程):

Hello world 0_0|||

 

参考博文:https://www.jianshu.com/p/925dba9f5969

 

画外音:

保持积极,保持锻炼,保持刻苦。

【多线程编程】--任务调度@Scheduled、ScheduledThreadPoolExecutor、quartz、xxl-job 目录一、springboot集成@Scheduled注解1.1、集成@Scheduled注解方法1.2、集成@Scheduled注解优劣点1.3、集成@Scheduled注解改进1.4、集成@Scheduled注解优缺点汇总二、springboot使用ScheduledThreadPoolExecutor定时调度2.1、ScheduleAtFixedRate方法2.2、ScheduleWithFixedDelay方法三、springboot集成quartz3.1、简单实现3.2、quartz优缺点四、任务调 阅读详情

相关推荐

深入解析 ScheduledThreadPoolExecutor:任务调度与线程池的完美结合

是一个功能强大的工具,它结合了线程池的高效性和任务调度的灵活性。通过合理配置线程池的大小和任务的执行方式,我们可以轻松实现复杂的并发任务调度。无论是延迟任务还是周期性任务,都能提供简洁而高效的解决方案。希望本文的介绍和实例能帮助你更好地理解和使用,提升你的并发编程能力。

2501_90323865的博客 507

Executor多线程与定时任务

点击上方“罗晓胜”,马上关注,您的支持对我帮助很大 上期文章 Stream操作 有趣问题——赛马游戏 / 前言 / 老在听人说多线程,那么啥是多线程,定时任务又是怎么一会儿事,本文会简单介绍多线程的创建和使用,以及定时任务的到底是怎么在使用和工作,更加详细的介绍会在java并发连载文章中介绍。 / 正文 / 创建定时任务的方式很多,常见的如Spring定时任务,Executors定时任务,还有其他定时任务。 Spr...

微信公z号: 罗晓胜,分享技术干货和有趣视频​ 2120

ScheduledThreadPool,schedule,scheduleAtFixedRate,scheduleWithFixedDelay 实例

public class ScheduledThreadPoolTest { public static final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); public static void main(String[] args) { ScheduledThreadPoolT...

Top5软件工程硕士,先后在京东、字节从事多年Java后端开发、实时和离线大数据开发 1125

ScheduledThreadPoolExecutor源码和误区详解

1.ScheduledThreadPoolExecutor 1.概述 ScheduledThreadPoolExecutor继承了ThreadPoolExecutor,在很多方法的实现上和ThreadPoolExecutor是一致或者相似的 ​ 同时还实现了ScheduledExecutorService接口,这个接口中的四个方法,才是ScheduledThreadPoolExecutor的意义,包含四个延时任务相关的方法 ​ ScheduledThreadPoolExecutor就是一..

weixin_56892092的博客 885

详解一典型的反激式开关电源方案

如图,在某系统方案上看到下图所示的单端反激式开关电源方案。

alala120的博客 1万+

纯JS实现SM3加密算法(兼容IE浏览器)

纯JS实现SM3加密,IE、谷歌、火狐等浏览器可以直接使用。

qianpou的博客 7363

JAVA线程池:ScheduledThreadPoolExecutor

前言 自JDK1.5开始,JDK提供了ScheduledThreadPoolExecutor类来支持周期性任务的调度。在这之前的实现需要依靠Timer和TimerTask或者其它第三方工具来完成。但Timer有不少的缺陷: Timer是单线程模式; 如果在执行任务期间某个TimerTask耗时较久,那么就会影响其它任务的调度; Timer的任务调度是基于绝对时间的,对系统时间敏感; Timer不会捕获执行TimerTask时所抛出的异常,由于Timer是单线程,所以一旦出现异常,则线程就会终止,其

青衫烟雨客的专栏 1万+

【数据库】SQL Server 2008 R2 安装全流程详解与常见问题避坑指南

本文详细解析了SQL Server 2008 R2的完整安装流程与核心配置。从安装前的系统兼容性检查、.NET Framework依赖准备,到图文详解实例配置、混合身份验证模式设置等关键步骤,并提供了安装失败、服务无法启动等高频问题的排查与避坑指南,帮助用户顺利完成部署。

java5的博客 1250

高并发编程之ScheduledThreadPoolExecutor讲解

一、ScheduledThreadPoolExecutor介绍 ScheduledThreadPoolExecutor,它可另行安排在给定的延迟后运行命令,或者定期执行命令。需要多个辅助线程时,或者要求 ThreadPoolExecutor 具有额外的灵活性或功能时,此类要优于Timer。 二、ScheduledThreadPoolExecutor相对于Timer的优势 ScheduledThreadPoolExecutor是一个使用线程池执行定时任务的类,相较于Java中提供的另一个执行定时任务的类Tim

s_156的博客 3012

OpenCV 常用的API总结(迅速查询)

OpenCV基本操作 openCV安装 读取图片(IO操作) 绘制集合图形 图像加法以及混合操作 OpenCV图像处理 图像几何变换 形态学操作 图像平滑 直方图 边缘检测 模板匹配 傅里叶变换 轮廓检测 图像分割 图像特征提取 SIFT检测关键点 视频读写............

Peyzhang的博客 3938

ARM和FPGA之间的通信(硬件原理图篇)

设计该开发板的初衷是为了学习,但也希望今后能扩展其功能,看到大家都在diy示波器,自己也非常冲动的想DIY一把,于是呼选了arm+fpga的方案,fpga主要用来实现数据的高速采样,而ARM则提供数据的显示,以及一些人机交互的功能。那么该方案中最重要的地方就是ARM和FPGA之间的通信如何实现了。在网上查了很多的资料,有说将FPGA作为ARM的一个外设,可以通过DMA的方式来直接访问;也有说把FP

屌yy的博客 5万+

ScheduledThreadPoolExecutor

public class ScheduledThreadPoolExecutor extends ThreadPoolExecutor implements ScheduledExecutorService { public interface ScheduledExecutorService extends ExecutorService { ScheduledExecutorService多了...

mingwulipo的博客 346

LeRobot 入门教程(七)数据集

LeRobot Dataset v3.0 是机器人学习数据的标准化格式,支持多模态时间序列数据和视频的统一访问。该版本通过基于文件的存储(Parquet/MP4)、关联元数据和Hub原生流式处理等新特性,显著提升了性能并降低了存储开销。文档详细介绍了格式设计、安装使用、数据记录与加载方法,以及从v2.1迁移到v3.0的步骤,特别针对大型数据集(如DROID 1.0.1)的处理提供了SLURM集群移植方案。v3.0通过优化文件组织和元数据管理,实现了更快的加载速度、更高的内存效率和更好的可扩展性。

2506_90492529的博客 2062

Java多线程 ScheduledThreadPoolExecutor 计划任务类的使用

Java多线程 ScheduledThreadPoolExecutor 计划任务类的使用

qq_43679366的博客 202

LPDDR6来了!到底比LPDDR5/5X强在哪?从速度到总线,技术细节一次说清!

LPDDR6不仅仅是速度快点、位宽大点那么简单,它是一次架构级的革新,从引脚、总线、时钟管理到Burst协议全部升级。🎯我们正在迈入一个“AI优先”的时代,内存架构也必须跟上。对于做芯片、做整机、做系统的你,理解LPDDR6的技术变化,提前规划测试方案,是现在就该启动的动作!

weixin_43199439的博客 1299

高云FPGA系列教程(1):FPGA和ARM开发环境搭建

至此,高云FPGA和MCU开发环境就搭建完成了,整体还是比较简单的,几乎是一键完成,下一篇文章我们进行实际的FPGA和MCU开发。本文是高云FPGA系列教程的第1篇文章。

whik1194的博客 6206

java timer schedule 通知主线程,使用Timer和ScheduledThreadPoolExecutor执行定时任务

Java使用Timer和ScheduledThreadPoolExecutor执行定时任务定时任务是在指定时间执行程序,或周期性执行计划任务。Java中实现定时任务的方法有很多,主要JDK自带的一些方法以及开源程序如Qurtz。>>Timer和TimerTaskTimer只是充当了一个执行者的角色,真正的任务逻辑是通过一个叫做TimerTask的抽象类完成的,TimerTask也是ja...

weixin_28708781的博客 688

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

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

12 多线程与高并发 - ScheduledThreadPoolExecutor 源码解析

12 多线程与高并发 - ScheduledThreadPoolExecutor 源码解析

刘元雄 565

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

深度学习工具包 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")

【多线程编程】--任务调度类ThreadPoolTaskScheduler、ScheduledThreadPoolExecutor解析

springboot的常见的任务调度这篇文章介绍了一些常见的任务调度技术方法。接下来,将会对ThreadPoolTaskScheduler、ScheduledThreadPoolExecutor进行对比。通过简单使用、源码实现、优缺点等来分析,以便在各种应用场景上使用相应技术。下面介绍的技术主要是针对 非分布式环境下可以考虑采用。ScheduledThreadPoolExecutor适用场景:主要是延迟一次性任务、周期性任务;

寻梦友的博客 3127

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

ScheduledThreadPoolExecutor定时任务:

和timerTask的区别: ScheduledThreadPool是在JDK1.5开始的. Timer ScheduledThreadPoolExecutor 单线程 多线程 单个任务执行时间影响其他任务调度 多线程,不会影响 基于绝对时间,对系统时间敏感 基于相对时间 一旦执行任务出现异常不会捕获,一旦出现异常,线程终止;其他任务得不...

qq_37160920的博客 686

ScheduledThreadPoolExecutor源码分析

ScheduledThreadPoolExecutor 克服了传统 Timer 类的诸多弊端,其多线程执行模式极大地提升了任务调度的效率与灵活性,有效避免了单线程模式下任务串行执行所导致的相互干扰问题。

程序员小潘 1140

java多线程组件三:ScheduledThreadPoolExecutor

在实际的情况中可能会需要有的线程是定期执行的,有的线程是只执行一次,如果通过Timer去触发,会涉及线程的切换以及线程安全问题,这对这种情况从jdk1.5开始添加了ScheduledThreadPoolExecutor 组件,这种组件主要就是用来解决前面出现的问题,通过这个组件即可以定期的去执行一个任务,也可以只执行一次,也可以把这两种情况一起使用,为了演示这个组件的使用,写了一个非常简单的小例子

不积跬步,无以至千里;不积小流,无以成江海! 1万+

java&android线程池-Executor框架之ThreadPoolExcutor&ScheduledThreadPoolExecutor浅析(多线程编程之三)

java多线程-概念&amp;创建启动&amp;中断&amp;守护线程&amp;优先级&amp;线程状态(多线程编程之一)java多线程同步以及线程间通信详解&amp;消费者生产者模式&amp;死锁&amp;Thread.join()(多线程编程之二)java&amp;android线程池-Executor框架之ThreadPoolExcutor&amp;ScheduledThreadPoolEx...

zejian的博客 2万+

第十七章 Java多线程--线程池-ScheduledThreadPoolExecutor

ScheduleThreadPoolExecutor 是 Java 平台上的 java.util.concurrent 包中的一个类,它是一个支持定时及周期性任务执行的线程池。ScheduleThreadPoolExecutor 实现了 ExecutorService 接口,并且扩展了 ThreadPoolExecutor,因此它不仅可以用来执行普通的异步任务,还可以调度任务在给定延迟后运行或定期运行。

Lin_Miao_09的博客 1493

33-ScheduledThreadPoolExecutor源码分析

ScheduledThreadPoolExecutor源码分析 自JDK1.5开始,JDK提供了ScheduledThreadPoolExecutor类来支持周期性任务的调度。在这之前的实现需要依靠Timer和TimerTask或者其它第三方工具来完成。但Timer有不少的缺陷: Timer是单线程模式,如果在执行任务期间某个TimerTask耗时较久,那么就会影响其它任务的调度; Time...

mbmispig的博客 306

Java Scheduler ScheduledExecutorService ScheduledThreadPoolExecutor示例

Welcome to the Java Scheduler Example. Today we will look into ScheduledExecutorService and it’s implementation class ScheduledThreadPoolExecutor example. 欢迎使用Java Scheduler示例。 今天,我们将研究ScheduledExecut...

从零开始的教程世界 1064
上一篇: 开发日常小结(28):Mybatis 分页插件 -- PageHelper 使用小结
下一篇: 后端日志(9):踏实追求
后台技术汇
博客等级 码龄11年 670粉丝 531原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

后台技术汇

对你的帮助,是对我的最好鼓励。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值