package com.timerTools;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class TestTimer {
Timer timer = new Timer();
//定时器,执行任务测试
public static void main(String[] args) {
new TestTimer().executeTask(3,null,1000,1000);
}
/**
* 定时器任务制定,执行
* @param tag: 0.在指定的时间里,执行指定的任务;
* 1.在指定的时间里,按照指定的延迟,重复执行指定任务;
* 2.从指定的延迟后,执行指定任务;
* 3.从指定的延迟后,按照指定的延迟,重复执行指定的任务。
*
* @param mydate:指定的执行时间。只有在tag等于0、1才需要指定。
* @param delay: 延迟执行时间,毫秒数。只有在tag等于1、3才需要指定。
* @param period:间隔执行时间,毫秒数。只有在tag等于4才需要指定。
*/
public void executeTask(int tag, Date mydate,long delay, long period) {
if(tag == 0){
timer.schedule(new DefineTimerTask(), mydate);
}else if(tag == 1){
timer.schedule(new DefineTimerTask(), mydate, period);
}else if(tag == 2){
timer.schedule(new DefineTimerTask(),delay);
}else if(tag == 3){
timer.schedule(new DefineTimerTask(),delay,period);
}else{
System.out.println("Error:输入的定时器参数无效!");
}
}
/**
* 执行的定时器任务
*/
private class DefineTimerTask extends TimerTask {
//执行的次数
boolean isTimes = true;
public void run() {
isTimes = isTimes();
if(isTimes){
System.out.println("执行定时器任务开始 :" + System.currentTimeMillis());
}else{
System.out.println("----------------- 执行定时器任务结束:" + System.currentTimeMillis());
timer.cancel();
}
}
}
//是否满足时间周期
public static boolean isTimes(){
boolean isTimes = false;
String newWeek = "2";
String times = "17:00-17:10,17:10-17:15,17:24-17:25,17:25-17:26"; //
String[] newWeeks = newWeek.split(",");
String[] timess = times.split(",");
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
int week = cal.get(Calendar.DAY_OF_WEEK);
if(week == 1){
week = 7;
}else{
week = week-1;
}
try {
for(int i=0;i<newWeeks.length;i++){
//是否是指定的周期
if(Integer.parseInt(newWeeks[i]) == week){
for(int j=0;j<timess.length;j++){
//是否是指定的时间段
if(isInDates(timess[j])){
System.out.println("----------------- 执行定时器任务时间:[" +timess[j]+"]");
return true;
}
}
}
}
} catch (Exception e) {}
return isTimes;
}
//比较两个时间是否存在交集
public static boolean isInDates(String times){
Date dt = new Date();
int strDateH = dt.getHours();
int strDateM = dt.getMinutes();
int strDateBeginH = Integer.parseInt(times.split("-")[0].split(":")[0]);
int strDateBeginM = Integer.parseInt(times.split("-")[0].split(":")[1]);
int strDateEndH = Integer.parseInt(times.split("-")[1].split(":")[0]);
int strDateEndM = Integer.parseInt(times.split("-")[1].split(":")[1]);
if((strDateH>=strDateBeginH && strDateH<=strDateEndH)){
if(strDateH>strDateBeginH && strDateH<strDateEndH){
return true;
}else if(strDateH==strDateBeginH && strDateM>strDateBeginM && strDateH<strDateEndH){
return true;
}else if(strDateH==strDateBeginH && strDateM==strDateBeginM && strDateH<strDateEndH){
return true;
}else if(strDateH==strDateBeginH && strDateM==strDateBeginM && strDateH<strDateEndH){
return true;
}else if(strDateH==strDateBeginH && strDateH==strDateEndH && strDateM<strDateEndM){
return true;
}else if(strDateH>strDateBeginH && strDateH==strDateEndH && strDateM<strDateEndM){
return true;
}else if(strDateH>strDateBeginH && strDateH==strDateEndH && strDateM==strDateEndM ){
return true;
}else if(strDateH>strDateBeginH && strDateH==strDateEndH && strDateM==strDateEndM){
return true;
}else{
return false;
}
}else{
return false;
}
}
} 相关推荐
从CCS3.3到CCS10:工程迁移与开发环境升级全攻略
本文详细介绍了从CCS3.3迁移到CCS10的完整流程与实战指南。针对老旧DSP项目,阐述了升级的必要性,并逐步指导CCS10的安装配置、界面操作、核心的工程移植步骤,以及移植后常见的代码调整与问题解决方案,帮助开发者高效完成开发环境升级,充分利用新版本的工具链提升开发效率。
Timer实现定时任务之指定时间执行、String转date、打印执行任务的时长
定时任务之指定时间执行任务
gsplat在windows本地部署
3DGS的cuda提效和优化内存的版本gsplat,使得在有一定GPU计算能力的电脑上也能够尝尝3DGS的效果。我在2025年的开年之初尝试配置过gsplat,由于过程中遇到很多问题,最终还是有一些windows上字符编码的问题,没有跑通,最近看gsplat的github更新了3DGUT,优化了反射和二次折射,以及适用于非线性相机模型,如鱼眼相机等。在data目录下下载好了360_v2的数据,进入之后images文件夹是原始分辨率的图像,images_2是下采样系数为2的数据,以此类推。
【Java】Timer和TimerTask详解
以下内容根据 The JavaTM Tutorial 和相关API doc翻译整理,以供日后参考: 1. 概览 Timer是一种定时器工具,用来在一个后台线程计划执行指定任务。它可以计划执行一个任务一次或反复多次。 TimerTask一个抽象类,它的子类代表一个可以被Timer计划的任务。 简单的一个例程: package test.util; import java.util.T
不用U盘也能装Ubuntu?手把手教你用EasyUEFI搞定双系统(附企业版资源)
本文详细介绍了无需U盘即可安装Ubuntu双系统的方法。通过使用EasyUEFI工具,在Windows环境下创建虚拟启动分区并配置UEFI引导,即可直接从硬盘启动Ubuntu安装程序。该方法特别适合开发者或技术爱好者快速搭建Linux开发环境,操作安全便捷,无需额外物理介质。
STM32CubeMX平台F4系列固件下载核心要点
详解STM32CubeMX平台下F4系列单片机的固件包下载方法与常见问题,重点讲解stm32cubemx固件包下载流程及配置技巧,帮助开发者快速完成开发环境搭建。
实现指定时间的系统定时任务Timer
指定时间定时任务
期权定价模型系列[11]三叉树期权定价[trinomial model ]
三叉树期权定价方法简介
java定时任务
1.TimerManager类 2.LyzTmerTask 3、LyzListener 4、web.xml配置LyzListener
中远麒麟堡垒机 SQL注入漏洞复现
中远麒麟堡垒机/baoleiji/api/tokens接口处存在sql注入漏洞,未经身份认证的攻击者可通过该漏洞获取数据库敏感信息及凭证,最终可能导致服务器失陷。
S32DS S32K312 LPSPI + DMA配置异步SPI
配置DMA->Specific Configuration->Dma Logic Channel->Configuration->Global。SpiPhyUnitMapping:将该配置Mapping到某一路Spi,此工程配置为Spi1,遂选择LPSPI_1。配置的该路SPI的片选ID,此处ID对应配置Pin脚时lpspi_pcs后的下表(本工程此处为PCS3)配置该路SPI对应的SPI硬件单元ID,本工程配置为Lpspi1,因此配置为CSIB1。首先配置SPI的Pin脚,此处使用的是LPSPI_1。
java Timer(定时调用、实现固定时间执行)
最近需要用到定时调用的功能。可以通过java的Timer类来进行定时调用,下面是有关Timer的一些相关知识。 其实就Timer来讲就是一个调度器,而TimerTask呢只是一个实现了run方法的一个类,而具体的TimerTask需要由你自己来实现,例如这样: Timer timer = new Timer(); timer.schedule(new TimerTask() { public void run() { System.out.println("11232
79、昇腾系列服务器/昇腾系列推理卡/昇腾系列嵌入式开发板+Dify+one api部署DeepSeek-R1-Distill-Qwen-32BW8A8+RAG本地模型知识库和负载均衡双实例
阶段,安装过程缺什么,,在docker外面git下源码,进入容器内部进行量化,这里的容器建议在创建个8卡的容器,双卡容器量化会显示npu显存不够,除非你用cpu转模型,我就懒得创建容器了,使用cpu量化吧,巨慢;创建容器,进入容器,计划使用两张昇腾NPU卡推理DeepSeek-R1-Distill-Qwen-32B的W8A8模型,所以构建的容器用两张卡,选6、7卡吧,0-6号卡可以跑文本嵌入模型、重排序模型;直接进入量化阶段,在容器外面操作即可,环境不用管,因为系统已经默认配置了环境,直接跳到。
多线程学习--写一个简单的定时器
package Demo2; //开源的工具quartz定义周一到周五执行周末不执行 import java.util.Date; import java.util.Timer; import java.util.TimerTask; public class TraditionalTimerTest { private static int count =0;
ssm框架搭建
这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载
深度学习工具包 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');```[](https://bitdeli.com/free "Bitdeli Badge")
Go进阶之定时器Timer
Go语言提供了两种定时器:一次性定时器(Timer)和周期性定时器(Ticker)。Timer通过NewTimer创建,在指定时间后触发一次事件,可通过Stop停止或Reset重置。Ticker会周期性触发,直到主动停止。Timer的核心实现包括:1) 运行时通过newTimer初始化并加入定时器堆;2) Stop操作通过标记状态实现停止;3) Reset实质是先Stop再重新激活。定时器内部使用锁保证并发安全,通过状态位(timerHeaped/timerModified等)管理生命周期,并采用序列号防止
复分析 阿尔福斯(Ahlfors) 第三版答案 英文
答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案
定时任务为什么不用Timer
在做定时任务的时候,有的同学可能能会用到Timer这个定时任务的辅助类, 但是使用它会有潜在的风险,风险如下, (1)时间计算不准确问题 因为Timer是以绝对时间计算定时任务的,会受到系统时间的影响,如果在任务执行期间,更改了系统时间,那么会 导致时间计算不准确问题,导致任务没用按找预定的时间执行。 (2)只能单任务执行 简单讲就是,只能一次执行一个任务,如果前一个任
老版QQ原生表情gif动态
这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。
java 多个timer_java循环调用多个timer定时器
通常在使用java实现定时任务时,有两种方法,一种是spring中的schedule(cron = " */5 * * * ?"),另一种就是java中的timer,timer+TimerTask配合实现,这里附上Timer对象的一些常用api1 Timer() 创建-个新计时器。2 Timer(boolean isDaemon) 创建一...
Timer定时器如何在时间范围内执行?
我们知道,Timer定时器是不支持时间范围内的执行,但是需求中有这样的情景,我们有一个预约扣款的需求,扣款成功后就会发短信,但是我们也不知道什么时候扣款成功,有时候半夜凌晨就会扣款成功,我们扣款成功判断这里用Timer定时器扫描的,每隔一段时间执行一次,但是半夜凌晨不希望扣款后发短信,以免打扰用户休息,要选择白天发短信,请看如下代码! //从配置文件中读取时间. public M...
java 一秒一次_java中的任务调度之Timer定时器(案例和源码分析)
定时器相信大家都不陌生,平时使用定时器就像使用闹钟一样,我们可以在固定的时间做某件事,也可以在固定的时间段重复做某件事,今天就来分析一下java中自带的定时任务器Timer。一、Timer基本使用在Java中为我们提供了Timer来实现定时任务,当然现在还有很多定时任务框架,比如说Spring、QuartZ、Linux Cron等等,而且性能也更加优越。但是我们想要深入的学习就必须先从最简单的开始...
java中的任务调度之Timer定时器(案例和源码分析)
定时器相信大家都不陌生,平时使用定时器就像使用闹钟一样,我们可以在固定的时间做某件事,也可以在固定的时间段重复做某件事,今天就来分析一下java中自带的定时任务器Timer。 一、Timer基本使用 在Java中为我们提供了Timer来实现定时任务,当然现在还有很多定时任务框架,比如说Spring、QuartZ、Linux Cron等等,而且性能也更加优越。但是我们想要深入的学习就必须先从最简单的...
常用技术-Timer定时器
主要介绍了java自带的定时器Timer的用法
WEB定时器-Timer
Java定时器(java.util.Timer)有定时触发计划任务的功能,通过配置定时器的间隔时间,在某一间隔时间段之后会自动有规律的调用预先所安排的计划任务(java.util.TimerTask)。另外,由于我们希望当Web工程启动时,定时器能自动开始计时,在整个Web工程的生命期里,定时器能在每晚深夜触发一次报表计算引擎。因此定时器的存放位置也值得考查,不能简单的存在于单个Servlet或J...
java timer定时任务_Java基础--定时任务Timer
一、Timer介绍java.util.Timerjava.util.TimerTaskTimer是一个定时器类,通过该类可以为指定的定时任务进行配置。TimerTask类是一个定时任务类,该类实现了Runnable接口,而且是一个抽象类,如下所示:public abstract class TimerTask implements Runnable可以通过继承该类,来实现自己的定时任务。Timer...
java任务调度之Timer定时器
定时器相信大家都不陌生,平时使用定时器就像使用闹钟一样,我们可以在固定的时间做某件事,也可以在固定的时间段重复做某件事,今天就来分析一下java中自带的定时任务器Timer。一、Timer基本使用在Java中为我们提供了Timer来实现定时任务,当然现在还有很多定时任务框架,比如说Spring、QuartZ、Linux Cron等等,而且性能也更加优越。但是我们想要深入的学习就必须先从最...
quarz设置定时器任务的有效时间段_Contiki的内核分析-定时器模型
导读 本文通过分析Contiki的源码,梳理Contiki的定时器模型中一共5个定时器的工作机制和原理。引入从本文开始,我们开始探究Contiki的5个定时器模型,遵循从易到难的原则,我们先开始两个基本的内核定时器timer和stimer,两者唯一的区别就是timer以内核tick为单位,stimer以秒为单位。因此只需要了解timer即可类推到stimer。在探究timer之前,我们先回顾一下...
java定时器_java任务调度之Timer定时器(案例和源码分析)
定时器相信大家都不陌生,平时使用定时器就像使用闹钟一样,我们可以在固定的时间做某件事,也可以在固定的时间段重复做某件事,今天就来分析一下java中自带的定时任务器Timer。一、Timer基本使用在Java中为我们提供了Timer来实现定时任务,当然现在还有很多定时任务框架,比如说Spring、QuartZ、Linux Cron等等,而且性能也更加优越。但是我们想要深入的学习就必须先从最简单的开始...
381



被折叠的 条评论
为什么被折叠?



