scheduleAtFixedRate与schedule区别

ScheduledExecutorService定时周期执行指定的任务 一:简单说明 ScheduleExecutorService接口中有四个重要的方法,其中scheduleAtFixedRate和scheduleWithFixedDelay在实现定时程序时比较方便。 下面是该接口的原型定义 java.util.concurrent.ScheduleExecutorService extendsExecutorService extendsExecut 阅读详情

schedule和scheduleAtFixedRate的区别:

如果指定开始执行的时间在当前系统运行时间之前,scheduleAtFixedRate会把已经过去的时间也作为周期执行(追赶性)而下一次执行的时间是参考上一次执行结束的时间,而schedule不会把过去的时间算上,会立即执行一次,下一次执行时间以上一次开始的时间作为参考。

/**
 * describe:不延时追赶性测试
 *
 * @author gary
 * @date 2019/02/20
 */
public class TimerTest2 {
    private static Timer timer = new Timer();
    static public class MyTask extends TimerTask {

        @Override
        public void run() {
            System.out.println("start!时间是:" + new Date());
            System.out.println("end!时间是:" + new Date());
        }
    }

    /**
     * 当前时间:Wed Feb 20 19:59:31 GMT+08:00 2019
     * start!时间是:Wed Feb 20 19:59:31 GMT+08:00 2019
     * end!时间是:Wed Feb 20 19:59:31 GMT+08:00 2019
     * start!时间是:Wed Feb 20 19:59:31 GMT+08:00 2019
     * end!时间是:Wed Feb 20 19:59:31 GMT+08:00 2019
     * start!时间是:Wed Feb 20 19:59:31 GMT+08:00 2019
     * end!时间是:Wed Feb 20 19:59:31 GMT+08:00 2019
     * start!时间是:Wed Feb 20 20:00:00 GMT+08:00 2019
     * end!时间是:Wed Feb 20 20:00:00 GMT+08:00 2019
     * @param args
     */
    public static void main(String[] args) {
        try {
            MyTask myTask = new MyTask();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String dataString = "2019-2-20 19:51:00";
            Date dateRef = sdf.parse(dataString);
            System.out.println("当前时间:" + new Date());
            //timer.schedule(myTask, dateRef, 3000);
            timer.scheduleAtFixedRate(myTask, dateRef, 3*60*1000);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
/**
 * describe:不延时追赶性测试
 *
 * @author gary
 * @date 2019/02/20
 */
public class TimerTest3 {
    private static Timer timer = new Timer();
    static public class MyTask extends TimerTask {

        @Override
        public void run() {
            System.out.println("start!时间是:" + new Date());
            System.out.println("end!时间是:" + new Date());
        }
    }

    /**
     * 当前时间:Wed Feb 20 20:03:41 GMT+08:00 2019
     * start!时间是:Wed Feb 20 20:03:41 GMT+08:00 2019
     * end!时间是:Wed Feb 20 20:03:41 GMT+08:00 2019
     * start!时间是:Wed Feb 20 20:06:41 GMT+08:00 2019
     * end!时间是:Wed Feb 20 20:06:41 GMT+08:00 2019
     * @param args
     */
    public static void main(String[] args) {
        try {
            MyTask myTask = new MyTask();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String dataString = "2019-2-20 19:51:00";
            Date dateRef = sdf.parse(dataString);
            System.out.println("当前时间:" + new Date());
            timer.schedule(myTask, dateRef, 3*60*1000);
            //timer.scheduleAtFixedRate(myTask, dateRef, 3*60*1000);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}

 

vue中使用video-player视频插件,第一次无法监听父组件穿过来的值解决办法 需求: 页面![在这里插入图片描述](https://img-blog.csdnimg.cn/20201208141906802.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0FfOTg4OA==,size_16,color_FFFFFF,t_70) 作品清单是从后端请求回来的不同格式的url,前端需求根据后缀动态判断格式,然后对齐进行下载和 阅读详情

相关推荐

Tailscale 自建 DERP 中继服务器

Tailscale自建DERP中继服务器

Accompagner的博客 4418

scheduleatfixedrate详解

通过本文的介绍,我们了解了的原理、使用方式以及一些需要注意的事项。在实际项目中,合理使用这个方法可以很方便地实现固定频率的定时任务。

聚娃科技开发者博客 7498

c++实现异步线程池并详细分析线程池析构流程

多线程编程是提高程序性能和响应能力的关键技术之一,异步线程池作为多线程编程的一种有效实现方式,能够管理和复用线程资源,避免频繁创建和销毁线程带来的开销。在本文中,我们将深入探讨如何实现一个异步线程池。

2301_76564925的博客 1608

scheduleAtFixedRate的用法(Java)

scheduleAtFixedRate(task,time,period)task-所要安排的任务 time-首次执行任务的时间 period-执行一次task的时间间隔,单位毫秒作用:时间等于或超过time首次执行task,之后每隔period毫秒重复执行taskimport java.text.SimpleDateFormat; import java.util.Calendar; impor...

星辰_大海的博客 4万+

Rocky Linux 9 离线环境Docker部署实战:从依赖打包到服务启动

本文提供了一份详尽的Rocky Linux 9离线环境Docker部署实战指南。针对无法访问外网的生产或内网服务器,文章详细讲解了如何在联网跳板机上下载Docker二进制包及所有系统依赖RPM包,并完成打包。随后,手把手指导在离线服务器上进行依赖安装、二进制文件部署、systemd服务配置、SELinux与防火墙调优,最终实现Docker服务的成功启动与验证。

weixin_28363123的博客 151

计算机网络-自顶向下方法 第三章课后习题答案(第七版)

复习题 R1. a) 就叫这个协议为简单传输协议STP(Simple Transport Protocol)。在发送方,STP从发送进程接收不超过1196字节的数据块、目标主机地址和目标端口号。STP向每个块添加一个4字节的头,并将目标进程的端口号放在头中。STP然后将目标主机地址和结果段提供给网络层。网络层将段交付给目的地主机的STP。目的主机基于STP检查段中的端口号,从段中提取数据,并将数据传递给由端口号标识的进程。 b) 在发送方,STP从发送进程接收不超过1192字节的数据块、目标主机地址和目标端

Erekilu的博客 2万+

Java定时任务之--schedule与scheduleAtFixedRate异同

schedule 执行任务超时,第N个任务会在 N-1个任务执行完成后,不做period等待,立即启动执行;N任务执行未超时,N+1个任务会在N任务执行完成后,等待period,再执行。

u011368399的专栏 3894

告别调参烦恼:用Simulink手把手实现自适应模糊PID温度控制(附模型下载)

本文详细介绍了如何使用Simulink实现自适应模糊PID温度控制,解决传统PID调参难题。通过模糊推理引擎动态调整PID参数,系统能自动适应不同工况,显著提升控制精度和响应速度。文章包含完整的建模步骤、参数优化技巧和工业应用扩展,并附赠可下载模型,帮助工程师快速掌握这一智能控制技术。

weixin_30872499的博客 161

ScheduledThreadPoolExecutor 中ScheduleAtFixedRate 和 ScheduleWithFixedDelay方法讲解

(2)若command执行的时间大于period,则command执行完,下一次任务将立即执行!ScheduleWithFixedDelay 每次执行时间为上一次任务结束起向后推一个时间间隔,即每次执行时间为:initialDelay, initialDelay+executeTime+delay, initialDelay+2。不管任务command执行的时间是多长,下一次任务的执行时间都是上一次任务执行完后在等待延迟间隔delay时间后执行下一次任务。taskExecutorTIme为任务执行的时间!

qq_43842093的博客 6392

Honeywell EPKS 核心功能块组态与执行调度实战解析

本文深入解析Honeywell EPKS系统的核心功能块组态与执行调度技术,涵盖控制模块(CM)、顺序控制模块(SCM)和输入输出模块(IOM)的配置方法。通过实战案例分享执行顺序(ORDERINCM)和CEE执行周期的优化策略,帮助工程师提升工业自动化系统的控制精度和运行效率。

weixin_28724319的博客 421

SAP采购含税价转换的底层逻辑解析:ABAP例程如何实现价税分离计算

本文深入解析SAP系统中采购含税价与不含税价的转换机制,重点介绍VOFM例程和ABAP代码实现价税分离计算的方法。通过详细讲解数学原理、税率体系及SAP定价引擎架构,为开发人员提供完整的解决方案,帮助提升采购业务中的价格处理效率和准确性。

weixin_29237635的博客 459

Timer的schedule和scheduleAtFixedRate方法的区别解析

在java中,Timer类主要用于定时性、周期性任务 的触发,这个类中有两个方法比较难理解,那就是schedule和scheduleAtFixedRate方法,在这里就用实例分析一下 (1)schedule方法:“fixed-delay”;如果第一次执行时间被delay了,随后的执行时间按照实际执行完成的时间点进行计算 (2)scheduleAtFixedRate方法:“fixed-rate”;如果第一次执行时间被delay了,随后的执行时间按照初始设定时间点进行计算,并且为了”catch up”会多

星星的技术专栏 6万+

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

Timer中schedule和scheduleAtFixedRate区别

schedule和scheduleAtFixedRate区别:  两种方法都是在延迟一段时间后,开始周期性执行任务,而又有一定细微的差别。可以看到,schedule在调用sched方法时,传入了负的period。 public void schedule(TimerTask task, long delay, long period) { if (delay < 0)

阿振的博客 1126

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

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

schedule和scheduleAtFixedRate区别

schedule和scheduleAtFixedRate的区别在于,如果指定开始执行的时间在当前系统运行时间之前,scheduleAtFixedRate会把已经过去的时间也作为周期执行,而schedule不会把过去的时间算上。 比如SimpleDateFormat fTime = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date d1 = fTim

weizaishouex2010的专栏 414

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Timer scheduleAtFixedRate与schedule的区别

scheduleAtFixedRate与schedule的区别主要是基准时间点以及第一次执行时执行的次数    timer.scheduleAtFixedRate(TimerTask, startTime, period): 如果执行时间executeTime&gt;startTime,则一执行就会从startTime开始(startTime时就会跑一次),每隔peroid跑TimerTa...

进击的莱鸟 428

schedule、scheduleAtFixedRate和scheduleWithFixedDelay的区别

最近使用java中的定时任务时,对于标题中的几个方法有点懵,故而记录一下。 schedule(commod,delay,unit) ,这个方法是说系统启动后,需要等待多久执行,delay是等待时间。只执行一次,没有周期性。 举个栗子:火箭发射,delay=10秒,发射准备好了之后,开始读秒:10,9,8,,,1,发射。piu~,任务完成,回家吃饭。 scheduleAtFixedRa

yuzjang的专栏 7568

schedule和scheduleAtFixedRate的区别

schedule(TimerTask task, long delay)           Schedules the specified task for execution after the specified delay. schedule(TimerTask task, long delay, long period)           Sc

choclover的专栏 1206

Timer的schedule与scheduleAtFixedRate的区别(三)

schedule与scheduleAtFixedRate的区别 两种情况看区别 1.首次计划执行的时间早于当前的时间 - schedule方法 “fixed-delay”;如果第一次执行时间被delay了,随后的执行时间按照==上一次实际执行完成的时间点==进行计算。 demo 代码 package lxd.timer.demo; import java.text.Sim...

飞鸟的轨迹 255

Timer的schedule和scheduleAtFixedRate区别

Timer的schedule和scheduleAtFixedRate个人理解。 schedule的下次开始时间是根据结束时间来看的,你设置一个间隔2秒的任务,但是每个任务需要执行的时间需要5秒,他会判断中间的两次任务开始时间已经错过了,他就会丢弃这些任务,进行下次还未开始的任务。scheduleAtFixedRate是根据开始时间来看的,你设置一个间隔2秒的任务,同样每个任务执行时间是5秒,等这次任务执行完后,下次任务的开始时间已经过去了,但是他会立马执行轮到的那个任务,不会丢弃,会延后。 ...

一只猿Hou的博客 517

Time schedule和scheduleAtFixedRate区别

schedule和scheduleAtFixedRate的区别在于,如果指定开始执行的时间在当前系统运行时间之前,scheduleAtFixedRate会把已经过去的时间也作为周期执行,而schedule不会把过去的时间算上。 比如 SimpleDateFormat fTime = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date d1 = fTi

kjfcpua的专栏 1941

Timer的scheduleAtFixedRate和schedule区别

Timer类  Timer类是进行任务调度的类,用来管理周期性任务的执行。scheduleAtFxiedRate和schedule  在Timer类中有两个方法用来提交周期性任务, public void schedule(TimerTask task, long delay, long period) ;和 public void scheduleAtFixedRate(TimerTask t

yao123long的博客 668
上一篇: HashMap、ConcurrentHashMap、Hashtable简单分析以及简单实现HashMap
下一篇: 99首英文歌
gary0917
博客等级 码龄9年 20粉丝 50原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值