亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? timer.java

?? 164個java例程
?? JAVA
字號:
/* * Copyright (c) 2000 David Flanagan.  All rights reserved. * This code is from the book Java Examples in a Nutshell, 2nd Edition. * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied. * You may study, use, and modify it for any non-commercial purpose. * You may distribute it non-commercially as long as you retain this notice. * For a commercial use license, or to purchase the book (recommended), * visit http://www.davidflanagan.com/javaexamples2. */package com.davidflanagan.examples.thread;import java.util.Date;import java.util.TreeSet;import java.util.Comparator;/** * This class is a simple implementation of the Java 1.3 java.util.Timer API **/public class Timer {    // This sorted set stores the tasks that this Timer is responsible for.    // It uses a comparator (defined below) to sort the task by execution time.    TreeSet tasks = new TreeSet(new TimerTaskComparator());    // This is the thread the timer uses to execute the tasks    TimerThread timer;    /** This constructor create a Timer that does not use a daemon thread */    public Timer() { this(false); }    /** The main constructor: the internal thread is a daemon if specified */    public Timer(boolean isDaemon) {	timer = new TimerThread(isDaemon);  // TimerThread is defined below	timer.start();                      // Start the thread running    }    /** Stop the timer thread, and discard all scheduled tasks */    public void cancel() {	synchronized(tasks) {     // Only one thread at a time!	    timer.pleaseStop();   // Set a flag asking the thread to stop	    tasks.clear();        // Discard all tasks	    tasks.notify();       // Wake up the thread if it is in wait().	}    }    /** Schedule a single execution after delay milliseconds */    public void schedule(TimerTask task, long delay) {	task.schedule(System.currentTimeMillis() + delay, 0, false);	schedule(task);    }    /** Schedule a single execution at the specified time */    public void schedule(TimerTask task, Date time) {	task.schedule(time.getTime(), 0, false);	schedule(task);    }    /** Schedule a periodic execution starting at the specified time */    public void schedule(TimerTask task, Date firstTime, long period) {	task.schedule(firstTime.getTime(), period, false);	schedule(task);    }    /** Schedule a periodic execution starting after the specified delay */    public void schedule(TimerTask task, long delay, long period) {	task.schedule(System.currentTimeMillis() + delay, period, false);	schedule(task);    }    /**      * Schedule a periodic execution starting after the specified delay.     * Schedule fixed-rate executions period ms after the start of the last.     * Instead of fixed-interval executions measured from the end of the last.     **/    public void scheduleAtFixedRate(TimerTask task, long delay, long period) {	task.schedule(System.currentTimeMillis() + delay, period, true);	schedule(task);    }    /** Schedule a periodic execution starting after the specified time */    public void scheduleAtFixedRate(TimerTask task, Date firstTime,				    long period)    {	task.schedule(firstTime.getTime(), period, true);	schedule(task);    }    // This internal method adds a task to the sorted set of tasks    void schedule(TimerTask task) {	synchronized(tasks) {  // Only one thread can modify tasks at a time!	    tasks.add(task);   // Add the task to the sorted set of tasks	    tasks.notify();    // Wake up the thread if it is waiting	}    }    /**      * This inner class is used to sort tasks by next execution time.     **/    static class TimerTaskComparator implements Comparator {	public int compare(Object a, Object b) {	    TimerTask t1 = (TimerTask) a;	    TimerTask t2 = (TimerTask) b;	    long diff = t1.nextTime - t2.nextTime;	    if (diff < 0) return -1;	    else if (diff > 0) return 1;	    else return 0;	}	public boolean equals(Object o) { return this == o; }    }    /**     * This inner class defines the thread that runs each of the tasks at their     * scheduled times     **/    class TimerThread extends Thread {	// This flag is will be set true to tell the thread to stop running.	// Note that it is declared volatile, which means that it may be 	// changed asynchronously by another thread, so threads must always	// read its true value, and not used a cached version.	volatile boolean stopped = false;  	// The constructor	public TimerThread(boolean isDaemon) { setDaemon(isDaemon); }	// Ask the thread to stop by setting the flag above	public void pleaseStop() { stopped = true; }	// This is the body of the thread	public void run() {	    TimerTask readyToRun = null;  // Is there a task to run right now?	    // The thread loops until the stopped flag is set to true.	    while(!stopped) {		// If there is a task that is ready to run, then run it!		if (readyToRun != null) { 		    if (readyToRun.cancelled) {  // If it was cancelled, skip.			readyToRun = null;			continue;		    }		    // Run the task.		    readyToRun.run();		    // Ask it to reschedule itself, and if it wants to run 		    // again, then insert it back into the set of tasks.		    if (readyToRun.reschedule())			schedule(readyToRun);		    // We've run it, so there is nothing to run now		    readyToRun = null;		    // Go back to top of the loop to see if we've been stopped		    continue;		}		// Now acquire a lock on the set of tasks		synchronized(tasks) {		    long timeout;  // how many ms 'till the next execution?		    if (tasks.isEmpty()) {   // If there aren't any tasks			timeout = 0;  // Wait 'till notified of a new task		    }		    else {			// If there are scheduled tasks, then get the first one			// Since the set is sorted, this is the next one.			TimerTask t = (TimerTask) tasks.first();			// How long 'till it is next run?			timeout = t.nextTime - System.currentTimeMillis();			// Check whether it needs to run now			if (timeout <= 0) {			    readyToRun = t;  // Save it as ready to run			    tasks.remove(t); // Remove it from the set			    // Break out of the synchronized section before			    // we run the task			    continue;			}		    }		    // If we get here, there is nothing ready to run now,		    // so wait for time to run out, or wait 'till notify() is		    // called when something new is added to the set of tasks.		    try { tasks.wait(timeout); }		    catch (InterruptedException e) {}		    // When we wake up, go back up to the top of the while loop		}	    }	}    }        /** This inner class defines a test program */    public static class Test {	public static void main(String[] args) {	    final TimerTask t1 = new TimerTask() { // Task 1: print "boom"		    public void run() { System.out.println("boom"); }		};	    final TimerTask t2 = new TimerTask() { // Task 2: print "BOOM"		    public void run() { System.out.println("\tBOOM"); }		};	    final TimerTask t3 = new TimerTask() { // Task 3: cancel the tasks		    public void run() { t1.cancel(); t2.cancel(); }		};	    	    // Create a timer, and schedule some tasks	    final Timer timer = new Timer();	    timer.schedule(t1, 0, 500);     // boom every .5sec starting now	    timer.schedule(t2, 2000, 2000); // BOOM every 2s, starting in 2s	    timer.schedule(t3, 5000);       // Stop them after 5 seconds	    // Schedule a final task: starting in 5 seconds, count	    // down from 5, then destroy the timer, which, since it is	    // the only remaining thread, will cause the program to exit.	    timer.scheduleAtFixedRate(new TimerTask() {		    public int times = 5;		    public void run() {			System.out.println(times--);			if (times == 0) timer.cancel();		    }		}, 				      5000,500);	}    }}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
粉嫩av亚洲一区二区图片| 久久精品99国产精品| 国产精品三级久久久久三级| 精品第一国产综合精品aⅴ| 日韩欧美你懂的| 精品免费国产二区三区| 26uuu精品一区二区| 久久久精品国产99久久精品芒果| 久久亚洲一级片| 国产日韩一级二级三级| 国产精品成人午夜| 亚洲欧美欧美一区二区三区| 一区二区高清视频在线观看| 午夜电影网一区| 精品一区二区三区久久| 国产一二三精品| 91亚洲精品一区二区乱码| 色婷婷精品大在线视频| 欧美日韩亚洲综合一区| 精品国产91久久久久久久妲己| 久久新电视剧免费观看| 中文字幕日本乱码精品影院| 亚洲国产va精品久久久不卡综合| 日本特黄久久久高潮| 国产一区二区在线视频| 91麻豆.com| 精品免费日韩av| 国产日韩精品一区二区三区在线| 亚洲免费av高清| 麻豆精品一区二区av白丝在线| 国产精品99久久久久| 91亚洲国产成人精品一区二区三| 欧美性猛交xxxx黑人交| 26uuu久久天堂性欧美| 亚洲精品免费在线| 美女视频黄久久| 91福利资源站| 国产无人区一区二区三区| 亚洲国产日韩a在线播放| 国产精品资源在线看| 欧美色图片你懂的| 国产欧美一区二区三区在线老狼| 亚洲电影激情视频网站| 国产激情视频一区二区在线观看| 欧美日韩亚洲另类| 国产精品久久久久久久久免费桃花 | 国产网站一区二区| 亚洲国产一区二区三区青草影视| 国产成人av电影免费在线观看| 精品视频全国免费看| 国产精品久久久久久户外露出| 日韩国产欧美视频| 色综合久久久久久久| 26uuu国产电影一区二区| 午夜久久久久久久久| 91麻豆高清视频| 国产欧美一二三区| 久久精品噜噜噜成人av农村| 欧美日韩国产精品成人| 亚洲综合免费观看高清在线观看| 成人精品视频网站| 国产婷婷一区二区| 国内精品自线一区二区三区视频| 日韩一区二区三区在线| 五月婷婷激情综合| 欧美日韩一级黄| 亚洲一区二三区| 欧美在线一区二区三区| 亚洲精品美国一| 91论坛在线播放| 亚洲免费资源在线播放| 一本色道亚洲精品aⅴ| 亚洲视频中文字幕| 色成人在线视频| 亚洲人妖av一区二区| 99精品偷自拍| 亚洲蜜桃精久久久久久久| 日本道色综合久久| 亚洲精品免费在线| 欧美精品1区2区3区| 亚洲第一成年网| 4hu四虎永久在线影院成人| 日本中文在线一区| 欧美大尺度电影在线| 国产精品一区二区男女羞羞无遮挡| 久久久噜噜噜久久人人看| 丰满白嫩尤物一区二区| 日韩美女啊v在线免费观看| 91成人看片片| 狠狠色狠狠色合久久伊人| 亚洲精品一线二线三线无人区| 国产精品99久久不卡二区| 国产精品美日韩| 在线观看亚洲专区| 日本午夜一本久久久综合| 精品成人免费观看| 99re成人在线| 亚洲国产精品一区二区久久| 制服视频三区第一页精品| 国产在线视频一区二区| 国产精品你懂的在线| 欧美视频一区二区| 精品一区二区三区视频在线观看| 国产精品午夜在线观看| 色猫猫国产区一区二在线视频| 天堂一区二区在线免费观看| 久久网这里都是精品| 色综合一区二区| 精品一区二区三区视频在线观看 | 国产精品国产三级国产a| 欧美日韩中文字幕一区| 狠狠色丁香久久婷婷综| 尤物在线观看一区| 2023国产精品视频| 在线观看一区二区视频| 国产成人综合视频| 日韩电影在线一区二区三区| 国产精品天天看| 91麻豆精品国产91久久久久久久久| 国产精品综合二区| 日韩国产欧美在线视频| 中文字幕在线观看不卡| 精品国产乱码久久久久久免费| 在线一区二区视频| 成人精品一区二区三区中文字幕| 麻豆91免费看| 视频一区二区中文字幕| 亚洲日本在线天堂| 亚洲国产精品ⅴa在线观看| 日韩欧美国产小视频| 欧美色中文字幕| 日本道免费精品一区二区三区| 成人精品鲁一区一区二区| 精品一区二区三区在线观看国产| 一区二区在线免费观看| 国产精品美女一区二区在线观看| 日韩精品一区二区三区中文不卡 | 91毛片在线观看| 国产**成人网毛片九色| 免费高清视频精品| 三级不卡在线观看| 天天av天天翘天天综合网| 亚洲免费观看高清完整版在线观看| 久久久午夜电影| 国产片一区二区| 中文字幕第一区| 国产精品福利一区| 中文欧美字幕免费| 国产精品天干天干在观线| 久久夜色精品国产噜噜av| 日韩精品在线网站| 欧美电影免费观看完整版| 日韩午夜电影在线观看| 欧美videossexotv100| 日韩一级片网站| 欧美精品一区二区精品网| 欧美不卡一二三| 久久精品在线观看| 亚洲国产成人自拍| 亚洲丝袜美腿综合| 一区二区三区美女视频| 亚洲一卡二卡三卡四卡无卡久久| 一区二区三区成人在线视频| 韩国av一区二区三区在线观看 | 精品久久久久久无| 久久嫩草精品久久久久| 国产精品丝袜久久久久久app| 国产精品理论在线观看| 亚洲日本丝袜连裤袜办公室| 午夜私人影院久久久久| 免费的国产精品| 豆国产96在线|亚洲| 在线视频亚洲一区| 日韩视频免费观看高清完整版在线观看| 日韩欧美成人午夜| 国产日产精品一区| 亚洲一区二区视频在线观看| 日韩电影在线观看一区| 国产99一区视频免费| 91麻豆精品一区二区三区| 666欧美在线视频| 久久精品男人天堂av| 亚洲黄色免费电影| 久久精品国产精品亚洲精品| 粗大黑人巨茎大战欧美成人| 在线观看一区日韩| 久久久亚洲综合| 午夜视频一区二区| 国产风韵犹存在线视精品| 欧美三级视频在线| 久久久久久久av麻豆果冻| 亚洲午夜视频在线| 国产91精品一区二区麻豆亚洲| 色天天综合色天天久久| 精品国产一区二区三区av性色| 一区二区三区欧美久久| 国产成人精品三级| 欧美一级二级三级蜜桃| 1区2区3区欧美| 国产乱淫av一区二区三区|