亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
国产一区二区影院| 91热门视频在线观看| 中文字幕在线不卡一区 | 国产乱理伦片在线观看夜一区| 中文字幕日本乱码精品影院| 日韩天堂在线观看| 在线一区二区三区做爰视频网站| 久久国产乱子精品免费女| 亚洲综合色婷婷| 国产欧美一区二区精品秋霞影院| 欧美一区二区成人6969| 色婷婷国产精品久久包臀 | 欧美曰成人黄网| 国产成人亚洲综合a∨婷婷| 天天综合天天做天天综合| 亚洲品质自拍视频网站| 久久只精品国产| 国产精品毛片a∨一区二区三区| 欧美老女人在线| 色噜噜狠狠一区二区三区果冻| 国产宾馆实践打屁股91| 久久99国产精品久久| 日本一区中文字幕 | 国产久卡久卡久卡久卡视频精品| 亚洲国产精品影院| 亚洲青青青在线视频| 国产精品久久久久久久久晋中 | 亚洲国产成人高清精品| 国产精品嫩草99a| 久久亚洲精华国产精华液 | 亚洲精品视频一区二区| 国产精品美女一区二区| 国产日产欧产精品推荐色| 日韩欧美久久久| 精品日韩一区二区三区| 日韩欧美一级在线播放| 日韩三级在线观看| 欧美成人一区二区三区在线观看| 91麻豆精品国产91久久久| 欧美片在线播放| 欧美久久婷婷综合色| 欧美日韩黄视频| 欧美高清精品3d| 91精品国产色综合久久不卡蜜臀| 欧美一区二视频| 日韩欧美国产一二三区| 26uuu成人网一区二区三区| 精品日韩一区二区三区免费视频| 久久伊人中文字幕| 中文字幕欧美日韩一区| 中文字幕欧美日本乱码一线二线| 中文幕一区二区三区久久蜜桃| 国产精品午夜在线| 亚洲三级电影全部在线观看高清| 综合久久综合久久| 亚洲综合一区二区| 日韩成人午夜精品| 国内精品在线播放| 高清久久久久久| 91美女视频网站| 欧美精品久久久久久久多人混战 | 另类专区欧美蜜桃臀第一页| 激情深爱一区二区| 成人avav影音| 欧美视频一区二区三区在线观看| 正在播放一区二区| 国产亚洲制服色| 亚洲精品国产第一综合99久久| 亚洲国产日韩a在线播放性色| 免费在线一区观看| 成人动漫视频在线| 欧美日韩一级大片网址| 欧美mv日韩mv亚洲| 国产精品色哟哟| 亚洲mv大片欧洲mv大片精品| 精品一区二区日韩| 91丨porny丨最新| 91精品国产综合久久精品图片 | 91免费视频网| 4438x成人网最大色成网站| ww亚洲ww在线观看国产| 中文字幕日韩精品一区| 丝袜a∨在线一区二区三区不卡| 国产精选一区二区三区| kk眼镜猥琐国模调教系列一区二区| 一卡二卡三卡日韩欧美| 91麻豆文化传媒在线观看| 在线中文字幕不卡| 精品盗摄一区二区三区| 亚洲精品视频在线看| 麻豆精品视频在线观看免费| 99re在线精品| 欧美mv日韩mv国产| 亚洲一区视频在线| 国产成人精品免费视频网站| 欧美亚洲一区二区在线| 久久精品在线免费观看| 午夜精品一区在线观看| 成人动漫精品一区二区| 日韩欧美一二区| 亚洲永久免费视频| 成人小视频免费观看| 日韩免费视频一区二区| 一区二区三区.www| 成a人片国产精品| 精品国产亚洲在线| 国产免费观看久久| 精品噜噜噜噜久久久久久久久试看 | 欧美变态tickle挠乳网站| 大胆欧美人体老妇| 亚洲欧洲精品天堂一级| 国产精品女同互慰在线看| 欧美日韩卡一卡二| 老司机一区二区| 久久久久久久网| 在线观看免费视频综合| 日本不卡中文字幕| 亚洲免费三区一区二区| 在线国产亚洲欧美| 韩国精品主播一区二区在线观看| 精品剧情v国产在线观看在线| 精品99一区二区三区| 欧美视频完全免费看| 成人久久久精品乱码一区二区三区| 蜜桃视频在线观看一区二区| 美女爽到高潮91| 亚洲国产精品自拍| 精品粉嫩aⅴ一区二区三区四区| 国产精品一区二区无线| 在线免费观看一区| 精品免费视频一区二区| 亚洲一区二区在线视频| 91玉足脚交白嫩脚丫在线播放| 国产午夜精品福利| 国产精品一区二区无线| 久久久亚洲国产美女国产盗摄| 美脚の诱脚舐め脚责91| 日韩免费观看2025年上映的电影| 水野朝阳av一区二区三区| 91精品免费在线| 久久激情五月婷婷| 在线电影院国产精品| 日本美女一区二区三区| 日韩欧美一区二区视频| 精品一区二区三区在线观看| 日韩你懂的在线观看| 国产在线日韩欧美| 久久精品一区八戒影视| 不卡一二三区首页| 亚洲人成精品久久久久久| 91福利在线免费观看| 亚洲一区二区三区视频在线| 欧美情侣在线播放| 免费在线观看精品| 亚洲精品在线观看网站| 国产精品亚洲一区二区三区妖精 | 91黄色激情网站| 夜夜爽夜夜爽精品视频| 欧美日韩国产一级| 乱中年女人伦av一区二区| 精品处破学生在线二十三| 91精品一区二区三区在线观看| 日本三级亚洲精品| 久久精品夜夜夜夜久久| www.一区二区| 亚洲韩国精品一区| 精品久久国产97色综合| 成人的网站免费观看| 亚洲国产日韩在线一区模特| 日韩一级黄色片| 国产福利91精品一区二区三区| 成人免费在线视频| 欧美日韩免费高清一区色橹橹 | 亚洲欧洲中文日韩久久av乱码| 欧美性色黄大片手机版| 激情六月婷婷久久| 中文字幕日本不卡| 91精品国产综合久久精品性色| 国产福利一区二区三区视频 | 久久久精品免费观看| 99视频国产精品| 免费久久精品视频| 国产精品免费视频网站| 欧美日韩国产成人在线免费| 国产乱子轮精品视频| 亚洲与欧洲av电影| 国产午夜精品一区二区三区视频 | 中国色在线观看另类| 欧美日韩的一区二区| 成人短视频下载| 麻豆成人91精品二区三区| 亚洲同性同志一二三专区| 欧美电视剧免费全集观看| 99国产麻豆精品| 国产在线播放一区二区三区| 亚洲一区二区三区四区五区中文| 国产欧美精品一区aⅴ影院 | 成人动漫精品一区二区| 日韩不卡在线观看日韩不卡视频| 中文字幕日本不卡|