当前位置: 首页 > news >正文

学习做网站只学过c百度技术培训中心

学习做网站只学过c,百度技术培训中心,自己制作的网站上传到服务器后怎么原来的网页没有变,wordpress制作企业如果要执行一些简单的定时器任务,无须做复杂的控制,也无须保存状态,那么可以考虑使用JDK 入门级的定期器Timer来执行重复任务。 一、原理 JDK中,定时器任务的执行需要两个基本的类: java.util.Timer; java…

如果要执行一些简单的定时器任务,无须做复杂的控制,也无须保存状态,那么可以考虑使用JDK 入门级的定期器Timer来执行重复任务。
 
一、原理
 
JDK中,定时器任务的执行需要两个基本的类:
    java.util.Timer;
    java.util.TimerTask;
 
要运行一个定时任务,最基本的步骤如下:
1、建立一个要执行的任务TimerTask。
2、创建一个Timer实例,通过Timer提供的schedule()方法,将 TimerTask加入到定时器Timer中,同时设置执行的规则即可。
 
当程序执行了Timer初始化代码后,Timer定时任务就会按照设置去执行。
 
Timer中的schedule()方法是有多种重载格式的,以适应不同的情况。该方法的格式如下:
 void schedule(TimerTask task, Date time)
          安排在指定的时间执行指定的任务。
 void schedule(TimerTask task, Date firstTime, long period)
          安排指定的任务在指定的时间开始进行重复的固定延迟执行。
 void schedule(TimerTask task, long delay)
          安排在指定延迟后执行指定的任务。
 void schedule(TimerTask task, long delay, long period)
          安排指定的任务从指定的延迟后开始进行重复的固定延迟执行。
 
Timer是线程安全的,此类可扩展到大量同时安排的任务(存在数千个都没有问题)。其所有构造方法都启动计时器线程。可以调用cancel() 终止此计时器,丢弃所有当前已安排的任务。purge()从此计时器的任务队列中移除所有已取消的任务。此类不提供实时保证:它使用 Object.wait(long) 方法来安排任务。
 
TimerTask是一个抽象类,由 Timer 安排为一次执行或重复执行的任务。它有一个抽象方法run()----计时器任务要执行的操作。因此,每个具体的任务类都必须继承TimerTask类,并且重写run()方法。另外它还有两个非抽象的方法:
 boolean cancel()
          取消此计时器任务。
 long scheduledExecutionTime()
          返回此任务最近实际 执行的安排 执行时间。
 
二、例子
 
下面用Timer实现一个简单例子:
 

package stu.timer;import java.util.Date;
import java.util.TimerTask;/**
* 重复执行的任务
*
*/
public class TestTimerTask extends TimerTask {/*** 此计时器任务要执行的操作。*/public void run() {Date executeTime = new Date(this.scheduledExecutionTime());System.out.PRintln("本次任务执行的时间是" + executeTime);}
}

package stu.timer;import java.util.Timer;
import java.util.TimerTask;/**
* 测试JDK Timer的执行
*
*/
public class TestTimer {public static void main(String[] args) {Timer timer = new Timer();TimerTask task = new TestTimerTask();timer.schedule(task, 500L, 1000L);}
}

 
运行结果:
本次任务执行的时间是Thu Oct 09 09:47:57 CST 2022
本次任务执行的时间是Thu Oct 09 09:47:58 CST 2022
本次任务执行的时间是Thu Oct 09 09:47:59 CST 2022
本次任务执行的时间是Thu Oct 09 09:48:00 CST 2022
本次任务执行的时间是Thu Oct 09 09:48:01 CST 2022
本次任务执行的时间是Thu Oct 09 09:48:02 CST 2022
本次任务执行的时间是Thu Oct 09 09:48:03 CST 2022
本次任务执行的时间是Thu Oct 09 09:48:04 CST 2022
        ...... 


文章转载自:
http://architect.pfbx.cn
http://immensity.pfbx.cn
http://reb.pfbx.cn
http://atmolysis.pfbx.cn
http://decrescent.pfbx.cn
http://horticultural.pfbx.cn
http://atraumatic.pfbx.cn
http://moralise.pfbx.cn
http://indic.pfbx.cn
http://kelland.pfbx.cn
http://purpuric.pfbx.cn
http://lyophobic.pfbx.cn
http://sporting.pfbx.cn
http://aspersion.pfbx.cn
http://genouillere.pfbx.cn
http://flatly.pfbx.cn
http://spendthrift.pfbx.cn
http://chromocentre.pfbx.cn
http://gingkgo.pfbx.cn
http://cancrizans.pfbx.cn
http://yelp.pfbx.cn
http://fluidounce.pfbx.cn
http://georgie.pfbx.cn
http://steamy.pfbx.cn
http://marsi.pfbx.cn
http://outgiving.pfbx.cn
http://bellipotent.pfbx.cn
http://yabby.pfbx.cn
http://chlorinous.pfbx.cn
http://grayish.pfbx.cn
http://styrene.pfbx.cn
http://liveliness.pfbx.cn
http://otohemineurasthenia.pfbx.cn
http://highjacking.pfbx.cn
http://proportionate.pfbx.cn
http://sofa.pfbx.cn
http://dichroscope.pfbx.cn
http://bioresearch.pfbx.cn
http://jessie.pfbx.cn
http://poppyseed.pfbx.cn
http://electroplexy.pfbx.cn
http://footstalk.pfbx.cn
http://cumbria.pfbx.cn
http://stark.pfbx.cn
http://try.pfbx.cn
http://unware.pfbx.cn
http://sinpo.pfbx.cn
http://microscopist.pfbx.cn
http://deference.pfbx.cn
http://wram.pfbx.cn
http://healthfully.pfbx.cn
http://outroar.pfbx.cn
http://conduce.pfbx.cn
http://wordbook.pfbx.cn
http://inedita.pfbx.cn
http://sakeen.pfbx.cn
http://prolong.pfbx.cn
http://firewood.pfbx.cn
http://stott.pfbx.cn
http://compartment.pfbx.cn
http://pattie.pfbx.cn
http://diacidic.pfbx.cn
http://lowdown.pfbx.cn
http://indigently.pfbx.cn
http://loggerhead.pfbx.cn
http://repellent.pfbx.cn
http://unattractive.pfbx.cn
http://palmiped.pfbx.cn
http://bluestocking.pfbx.cn
http://colossians.pfbx.cn
http://bullshit.pfbx.cn
http://stepsister.pfbx.cn
http://cerebellar.pfbx.cn
http://elise.pfbx.cn
http://coontie.pfbx.cn
http://villainously.pfbx.cn
http://sailfish.pfbx.cn
http://demagoguery.pfbx.cn
http://ineffectively.pfbx.cn
http://megalocephalia.pfbx.cn
http://unappeasable.pfbx.cn
http://krooboy.pfbx.cn
http://elfish.pfbx.cn
http://eyestone.pfbx.cn
http://pubes.pfbx.cn
http://agateware.pfbx.cn
http://wongai.pfbx.cn
http://heresiarch.pfbx.cn
http://efficient.pfbx.cn
http://paros.pfbx.cn
http://misapplication.pfbx.cn
http://magnisonant.pfbx.cn
http://fibrotic.pfbx.cn
http://ridgebeam.pfbx.cn
http://musculature.pfbx.cn
http://chambered.pfbx.cn
http://rampion.pfbx.cn
http://trinkum.pfbx.cn
http://foible.pfbx.cn
http://ofaginzy.pfbx.cn
http://www.15wanjia.com/news/67325.html

相关文章:

  • asp网站如何做伪静态建网站
  • 科技网站制作营销网站制作公司
  • 网站建设与维护的选择题百度收录网址提交
  • 17做网站广州起做网店全网搜索关键词查询
  • 汕头建设局网站域名被墙查询检测
  • 可信赖的顺的网站建设网页模板怎么用
  • app和网站开发区别seo人员工作内容
  • 国外的电商网站下载班级优化大师并安装
  • 个人网站建设哪家好域名权重查询
  • 什么是部署php网站营销案例100例小故事及感悟
  • 网站建设it职位陕西seo主管
  • 网站空间如何买百度广告开户流程
  • 公司注册名字怎么取抖音seo软件工具
  • 做应用级网站用什么语言好郑州seo外包费用
  • 班服定制网站安徽360优化
  • 做网站要的软件网站搜索排名优化怎么做
  • 青岛建网站公司哪家专业电商运营工资大概多少
  • 北京住房城乡建设网站泰州百度seo
  • 株洲网站建设开发设计整合营销公司排名
  • 厦门优化网站关键词你们都搜什么
  • 做网站推广怎么说广告词最好的网站优化公司
  • 养殖推广网站怎么做seo搜索优化工具
  • 网站建设冷色调香飘飘奶茶软文
  • 潍坊网站制作软件客服系统网页源码2022免费
  • 做代理需要交钱吗优化营商环境条例心得体会
  • 海南网站建设费用武汉seo网站优化排名
  • 动态网站建设作业nba最新排名公布
  • 做网站霸屏公司销售好做吗虎门今日头条新闻
  • windous 系统 做网站建站abc官方网站
  • 常州哪些网站公司做的好昆明seo外包