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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? timer.java

?? 共有164個(gè)java源程序
?? JAVA
字號(hào):
/* * 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);	}    }}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲国产精品一区二区久久| 日韩av高清在线观看| 精品一区二区av| 久久国产精品露脸对白| 欧美一区二区三区播放老司机| 欧美肥妇毛茸茸| 久久精品99久久久| 国产成都精品91一区二区三| 欧美日韩五月天| 久久91精品久久久久久秒播| 一区二区三区精密机械公司| 日韩一二三区视频| zzijzzij亚洲日本少妇熟睡| 国产综合一区二区| 国产精品第13页| 成人v精品蜜桃久久一区| 亚洲欧洲日韩av| 欧美日韩国产综合草草| 99久久夜色精品国产网站| 日韩欧美一区二区不卡| 欧美日韩精品三区| 日韩一区二区电影在线| 欧美极品xxx| 91国在线观看| 国产女人18毛片水真多成人如厕| 99国产精品久久久久久久久久| 日韩视频123| 91女神在线视频| 91欧美一区二区| 成人综合婷婷国产精品久久蜜臀 | 666欧美在线视频| 欧美日韩国产综合一区二区三区| 激情图片小说一区| 日韩一区二区免费在线观看| 91精品国产综合久久久久久久| 欧美一区二区视频网站| 色婷婷av久久久久久久| 另类综合日韩欧美亚洲| 国产不卡视频一区| 天天做天天摸天天爽国产一区 | 97aⅴ精品视频一二三区| 一区二区三区四区五区视频在线观看| 一区二区三区日韩欧美| 91成人免费电影| 91精品国产综合久久久久久| 欧美日韩久久久| 337p亚洲精品色噜噜狠狠| 精品成人私密视频| 亚洲人午夜精品天堂一二香蕉| 亚洲一区二区三区视频在线| 老司机精品视频在线| 精品1区2区3区| 国产精品国产三级国产aⅴ中文 | 久久麻豆一区二区| 亚洲高清在线精品| www.欧美精品一二区| 欧美色老头old∨ideo| 久久亚洲精精品中文字幕早川悠里| 亚洲综合无码一区二区| 国产91丝袜在线18| av在线不卡电影| 国产乱子轮精品视频| 久久久久国产精品麻豆ai换脸| 午夜久久久影院| √…a在线天堂一区| 韩国理伦片一区二区三区在线播放| 一本一本久久a久久精品综合麻豆| 久久久久国产精品麻豆ai换脸| 一本色道久久综合狠狠躁的推荐| 精品久久久久久综合日本欧美| 日韩精品福利网| 国产不卡高清在线观看视频| 成人av免费在线播放| 国产精品不卡视频| caoporn国产精品| 国产精品免费视频网站| 波多野结衣中文字幕一区| 91福利精品视频| 国产成人小视频| 久久精品一区四区| 韩国三级在线一区| 精品少妇一区二区三区在线播放| 91免费观看在线| 亚洲欧美日韩国产手机在线| 成人av免费观看| 精品精品国产高清a毛片牛牛| 久久精品二区亚洲w码| 午夜精品视频在线观看| 亚洲免费在线视频| 韩国欧美国产一区| 亚洲福利视频三区| 国v精品久久久网| 国产精品久久久久久户外露出| 色综合视频一区二区三区高清| 色综合天天综合网天天狠天天 | 中文字幕+乱码+中文字幕一区| 国产一区美女在线| 国产成人av电影在线| 伦理电影国产精品| 五月综合激情网| 欧美性欧美巨大黑白大战| 亚洲免费观看高清完整版在线| 欧美日韩免费观看一区二区三区 | 久久久久久黄色| 91麻豆精品国产91久久久久久| 国产一区二区导航在线播放| 亚洲一级二级三级| 国产精品久久久久久妇女6080| 欧美精品国产精品| 色狠狠综合天天综合综合| 久久成人av少妇免费| 亚洲二区视频在线| 1000部国产精品成人观看| 国产亚洲欧美一区在线观看| 国产精品久久久久久久久动漫| 91精品国产品国语在线不卡| 国产一区二区三区免费在线观看| 久久成人久久爱| 国产精品久久久久影院老司| 国产一区二区三区四| 日韩你懂的在线观看| 美女久久久精品| 欧美成人综合网站| 在线观看一区二区视频| 婷婷开心久久网| 亚洲成人1区2区| 日本视频免费一区| 制服视频三区第一页精品| 欧美一区二区免费观在线| 中日韩av电影| 亚洲欧美日韩国产中文在线| 岛国精品一区二区| 最新国产精品久久精品| 国产一区二区三区精品欧美日韩一区二区三区 | 91精品国产综合久久精品app| 国产欧美日韩另类视频免费观看| 欧美日韩国产系列| 成人av动漫在线| 色呦呦国产精品| 亚洲国产精品激情在线观看| 日韩女优av电影| 2022国产精品视频| 久久综合狠狠综合久久激情| 国产乱人伦精品一区二区在线观看| 97久久超碰精品国产| 日韩精品一区二区三区老鸭窝| 国产喂奶挤奶一区二区三区| 亚洲国产va精品久久久不卡综合| 日韩欧美高清dvd碟片| 日韩欧美美女一区二区三区| 国产精品视频在线看| 天天综合日日夜夜精品| 国产精品一级在线| 欧美精品国产精品| 亚洲视频一二三| 国产91清纯白嫩初高中在线观看| 欧美一区二区三区视频| 亚洲欧洲制服丝袜| 91蝌蚪porny成人天涯| 国产宾馆实践打屁股91| 678五月天丁香亚洲综合网| 亚洲成人一区在线| 在线观看免费成人| 国产精品一区二区91| 色呦呦国产精品| 欧美私模裸体表演在线观看| 蜜臀国产一区二区三区在线播放| 国产精品丝袜久久久久久app| 中文字幕av不卡| 日韩欧美亚洲另类制服综合在线| 欧美xxx久久| 91在线视频观看| 国产成人av电影免费在线观看| www.欧美精品一二区| 日韩一区二区三区四区五区六区| 三级欧美韩日大片在线看| ...中文天堂在线一区| 另类欧美日韩国产在线| 色综合久久天天| 国产精品一品二品| 久久国产精品色婷婷| 国产乱码精品一区二区三| 男女性色大片免费观看一区二区 | 7777女厕盗摄久久久| 成人在线视频一区| 久久99精品国产麻豆婷婷| 日日摸夜夜添夜夜添国产精品| 亚洲国产岛国毛片在线| 日韩一级完整毛片| 天天影视色香欲综合网老头| 欧美自拍偷拍午夜视频| 一区二区三区电影在线播| 亚洲风情在线资源站| 欧美中文字幕一区二区三区亚洲 | 不卡的电影网站| 亚洲免费电影在线| 日韩三级伦理片妻子的秘密按摩| 国产一区高清在线| 午夜欧美视频在线观看| 欧美大片免费久久精品三p |