最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java實(shí)現(xiàn)Timer的定時(shí)調(diào)度函數(shù)schedule的四種用法

 更新時(shí)間:2023年04月24日 14:22:06   作者:星辰_大海  
本文主要介紹了Java實(shí)現(xiàn)Timer的定時(shí)調(diào)度函數(shù)schedule的四種用法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

schedule的四種用法

schedule(task,time)

task-所安排的任務(wù)  time-執(zhí)行任務(wù)的時(shí)間

作用:在時(shí)間等于或者超過(guò)time的時(shí)候執(zhí)行且僅執(zhí)行一次

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
 
public class MyTimerTask extends TimerTask {
    private Integer cout = 0;
    @Override
    public void run() {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-DD HH:mm:ss");
        System.out.println("Current Time:"+format.format(calendar.getTime()));//獲取當(dāng)前系統(tǒng)時(shí)間
        System.out.println("NO.1");
    }
    public static void main(String[] args) {
        MyTimerTask task = new MyTimerTask();
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-DD HH:mm:ss");
        System.out.println(format.format(calendar.getTime()));
        calendar.add(Calendar.SECOND,3);//獲取距離當(dāng)前時(shí)間3秒后的時(shí)間
        Timer timer = new Timer();
        timer.schedule(task,calendar.getTime());
 
    }
}

schedule(task,time,period)

task-所要安排執(zhí)行的任務(wù) time-首次執(zhí)行任務(wù)的時(shí)間 period-執(zhí)行一次task的時(shí)間間隔,單位毫秒

作用:時(shí)間等于或者超過(guò)time首次執(zhí)行task,之后每隔period毫秒重復(fù)執(zhí)行一次任務(wù)

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
 
public class MyTimerTask extends TimerTask {
    private Integer cout = 0;
    @Override
    public void run() {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-DD HH:mm:ss");
        System.out.println("Current Time:"+format.format(calendar.getTime()));//獲取當(dāng)前系統(tǒng)時(shí)間
        System.out.println("NO.1");
    }
    public static void main(String[] args) {
        MyTimerTask task = new MyTimerTask();
        Calendar calendar= Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-DD HH:mm:ss");
        System.out.println(format.format(calendar.getTime()));
        calendar.add(Calendar.SECOND,3);//獲取距離當(dāng)前時(shí)間3秒后的時(shí)間
        Timer timer = new Timer();
       //timer.schedule(task,calendar.getTime());
        timer.schedule(task,calendar.getTime(),2000);
    }
}

schedule(task,delay)

task-所要安排的任務(wù)  delay-執(zhí)行任務(wù)前的延遲時(shí)間,單位毫秒

作用:等待delay毫秒后執(zhí)行僅執(zhí)行一次task

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
 
public class MyTimerTask extends TimerTask {
    @Override
    public void run() {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-DD HH:mm:ss");
        System.out.println("Current Time:"+format.format(calendar.getTime()));//獲取當(dāng)前系統(tǒng)時(shí)間
        System.out.println("NO.1");
    }
    public static void main(String[] args) {
        MyTimerTask task = new MyTimerTask();
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-DD HH:mm:ss");
        System.out.println(format.format(calendar.getTime()));
        //calendar.add(Calendar.SECOND,3);//獲取距離當(dāng)前時(shí)間3秒后的時(shí)間
        Timer timer = new Timer();
        //timer.schedule(task,calendar.getTime());
        //timer.schedule(task,calendar.getTime(),2000);
        timer.schedule(task,2000);
    }
}

schedule(task, delay,period)

作用:在等待delay毫秒后首次執(zhí)行task,每隔period毫秒重復(fù)執(zhí)行task

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
 
public class MyTimerTask extends TimerTask {
    @Override
    public void run() {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-DD HH:mm:ss");
        System.out.println("Current Time:"+format.format(calendar.getTime()));//獲取當(dāng)前系統(tǒng)時(shí)間
        System.out.println("NO.1");
    }
    public static void main(String[] args) {
        MyTimerTask task = new MyTimerTask();
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-DD HH:mm:ss");
        System.out.println(format.format(calendar.getTime()));
        //calendar.add(Calendar.SECOND,3);//獲取距離當(dāng)前時(shí)間3秒后的時(shí)間
        Timer timer = new Timer();
        //timer.schedule(task,calendar.getTime());
        //timer.schedule(task,calendar.getTime(),2000);
        //timer.schedule(task,2000);
        timer.schedule(task,2000,3000);
    }
}

到此這篇關(guān)于Java實(shí)現(xiàn)Timer的定時(shí)調(diào)度函數(shù)schedule的四種用法的文章就介紹到這了,更多相關(guān)Java schedule內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Mybatis多個(gè)字段模糊匹配同一個(gè)值的案例

    Mybatis多個(gè)字段模糊匹配同一個(gè)值的案例

    這篇文章主要介紹了Mybatis多個(gè)字段模糊匹配同一個(gè)值的案例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-09-09
  • springboot項(xiàng)目中常用的工具類和api詳解

    springboot項(xiàng)目中常用的工具類和api詳解

    在Spring Boot項(xiàng)目中,開發(fā)者通常會(huì)依賴一些工具類和API來(lái)簡(jiǎn)化開發(fā)、提高效率,以下是一些常用的工具類及其典型應(yīng)用場(chǎng)景,涵蓋 Spring 原生工具、第三方庫(kù)(如Hutool、Guava) 和 Java 自帶工具,本文給大家介紹springboot項(xiàng)目中常用的工具類和api,感興趣的朋友一起看看吧
    2025-04-04
  • java實(shí)現(xiàn)簡(jiǎn)易局域網(wǎng)聊天功能

    java實(shí)現(xiàn)簡(jiǎn)易局域網(wǎng)聊天功能

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)簡(jiǎn)易局域網(wǎng)聊天功能,使用UDP模式編寫一個(gè)聊天程序,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • SpringBoot之導(dǎo)入靜態(tài)資源詳解

    SpringBoot之導(dǎo)入靜態(tài)資源詳解

    今天帶大家學(xué)習(xí)SpringBoot導(dǎo)入靜態(tài)資源的過(guò)程,文中介紹的非常詳細(xì),對(duì)正在學(xué)習(xí)java的小伙伴們有很好地幫助,需要的朋友可以參考下
    2021-05-05
  • servlet監(jiān)聽器的學(xué)習(xí)使用(三)

    servlet監(jiān)聽器的學(xué)習(xí)使用(三)

    這篇文章主要為大家詳細(xì)介紹了servlet監(jiān)聽器學(xué)習(xí)使用的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-09-09
  • java 分割csv數(shù)據(jù)的實(shí)例詳解

    java 分割csv數(shù)據(jù)的實(shí)例詳解

    這篇文章主要介紹了java 分割csv數(shù)據(jù)的實(shí)例詳解的相關(guān)資料,這里提供了簡(jiǎn)單實(shí)例,需要的朋友可以參考下
    2017-07-07
  • Java8中forEach語(yǔ)句循環(huán)一個(gè)List和Map

    Java8中forEach語(yǔ)句循環(huán)一個(gè)List和Map

    這篇文章主要給大家介紹了關(guān)于Java8中forEach語(yǔ)句循環(huán)一個(gè)List和Map的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-02-02
  • Spring之Environment類的使用方式

    Spring之Environment類的使用方式

    這篇文章主要介紹了Spring之Environment類的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • Java Redis Redisson配置教程詳解

    Java Redis Redisson配置教程詳解

    這篇文章主要介紹了Java Redis Redisson配置教程,包括Session共享配置及其他Redisson的Config配置方式,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-08-08
  • java null轉(zhuǎn)換為字符串的三種方法

    java null轉(zhuǎn)換為字符串的三種方法

    在Java開發(fā)中,正確處理null值至關(guān)重要,以避免空指針異常,本文介紹了三種常見的null值轉(zhuǎn)字符串方法:三元運(yùn)算符、Objects.toString方法、String.valueOf方法,感興趣的可以了解一下
    2024-10-10

最新評(píng)論

平邑县| 承德县| 封开县| 邯郸市| 鹿泉市| 周至县| 青河县| 浦县| 昭平县| 湘乡市| 嘉荫县| 马边| 兴安县| 青浦区| 平凉市| 雅安市| 江门市| 承德县| 开封市| 吐鲁番市| 陵川县| 凤凰县| 灵武市| 砀山县| 石渠县| 仁布县| 松阳县| 团风县| 丰都县| 达日县| 陵川县| 额尔古纳市| 赞皇县| 科技| 武安市| 临汾市| 白城市| 五大连池市| 昂仁县| 富蕴县| 元谋县|