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

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

?? timer.java

?? JAVA 實例手冊源碼 Examples From Java Examples in a Nutshell, 2nd Edition
?? 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一区二区三区免费野_久草精品视频
精品亚洲成a人| 日韩视频一区二区三区| 亚洲精品一线二线三线| 天天影视网天天综合色在线播放| a亚洲天堂av| 亚洲人亚洲人成电影网站色| 国产一区二区在线电影| 日韩无一区二区| 久久精品国产一区二区三| 欧美日韩国产色站一区二区三区| 亚洲欧美日韩一区二区| 色综合久久综合| 一区二区三区欧美在线观看| 99精品国产视频| 亚洲乱码一区二区三区在线观看| bt欧美亚洲午夜电影天堂| 《视频一区视频二区| av毛片久久久久**hd| 成人免费在线观看入口| 欧美在线|欧美| 免费不卡在线观看| 国产精品美日韩| 欧美三级在线视频| 狠狠色丁香婷综合久久| 国产精品女同互慰在线看| 欧美精品在线一区二区三区| 日本亚洲欧美天堂免费| 国产三级一区二区三区| 成人丝袜高跟foot| 亚洲色大成网站www久久九九| 在线观看视频一区二区欧美日韩| 久久www免费人成看片高清| 欧美国产精品v| 日韩你懂的在线播放| 色网站国产精品| 国产高清视频一区| 日本不卡一二三区黄网| 久久久亚洲午夜电影| 欧美日韩1234| 91美女在线观看| 国产一区二区三区四| 日韩精品1区2区3区| 亚洲视频一二区| 国产喷白浆一区二区三区| 欧美va日韩va| 欧美一级久久久| 91社区在线播放| 国产suv精品一区二区6| 国产剧情一区二区三区| 久久99热国产| 老司机免费视频一区二区 | 日本不卡一二三区黄网| 一区二区三区 在线观看视频| 国产精品第四页| 国产精品久久久久久亚洲毛片 | 欧美日韩在线播放一区| 欧美亚洲综合一区| 91国产丝袜在线播放| 欧美日韩国产欧美日美国产精品| 欧美三区在线视频| 日韩欧美在线不卡| 国产午夜三级一区二区三| 国产精品伦一区二区三级视频| 日韩一区在线播放| 亚洲国产cao| 另类小说图片综合网| 国产福利一区在线观看| 色94色欧美sute亚洲13| 日韩欧美不卡在线观看视频| 久久综合久久综合久久| 久久精品夜夜夜夜久久| 亚洲一区二区三区四区的| 日韩成人av影视| 懂色av中文一区二区三区| 91影院在线免费观看| 欧美三级视频在线| 国产亚洲成年网址在线观看| 久久精品视频一区二区| 亚洲一级电影视频| 国产成人精品免费看| 欧美在线综合视频| 欧美激情一区三区| 日韩精品乱码免费| 色激情天天射综合网| 久久久久久久性| 日本aⅴ精品一区二区三区| 99久久精品免费| 91精品欧美福利在线观看| 国产精品女主播av| 国产精品99久久久久久似苏梦涵| 欧美福利视频导航| 亚洲欧洲精品成人久久奇米网| 看电影不卡的网站| 色婷婷精品久久二区二区蜜臂av | 91久久线看在观草草青青| 欧美一区二区免费观在线| 亚洲成人资源网| 欧洲精品一区二区三区在线观看| 国产婷婷色一区二区三区四区| 青草国产精品久久久久久| 色婷婷国产精品| 夜夜嗨av一区二区三区| 在线免费观看视频一区| 国产精品久99| 91在线视频免费观看| 精品av久久707| 国产精选一区二区三区| 亚洲国产精品高清| caoporn国产精品| 亚洲国产成人午夜在线一区| 国产一区二区三区精品欧美日韩一区二区三区 | 欧美影院精品一区| 日日摸夜夜添夜夜添精品视频| 欧美无人高清视频在线观看| 亚洲一区二区三区四区在线观看| 91国产视频在线观看| 日韩激情一区二区| 久久综合av免费| 北条麻妃国产九九精品视频| 亚洲卡通动漫在线| 欧美一区二区视频观看视频 | 91亚洲男人天堂| 1区2区3区精品视频| 欧美欧美欧美欧美| 久久国产夜色精品鲁鲁99| 日韩毛片在线免费观看| 欧美三日本三级三级在线播放| 91麻豆国产自产在线观看| 麻豆国产欧美一区二区三区| 国产精品美日韩| 精品久久久久久久久久久院品网| eeuss鲁一区二区三区| 日韩精品欧美成人高清一区二区| 久久久精品中文字幕麻豆发布| 91老师片黄在线观看| 国产一区二区伦理| 成人app软件下载大全免费| 日韩福利视频导航| 亚洲视频一区在线观看| 中文字幕乱码日本亚洲一区二区| 777色狠狠一区二区三区| 成人av资源在线| 91麻豆精品秘密| 91啪在线观看| 欧美综合色免费| 宅男在线国产精品| 91精品国产综合久久久久久漫画| 欧美亚洲图片小说| 欧美精品一卡二卡| 欧美精品一区二区三区高清aⅴ | 久久精品一区八戒影视| 久久久美女艺术照精彩视频福利播放| 日韩欧美国产wwwww| 久久久蜜桃精品| 中文字幕亚洲在| 亚洲成av人影院| 激情文学综合插| 成人国产一区二区三区精品| 91啪亚洲精品| 欧美一区二区啪啪| 国产女人aaa级久久久级| 亚洲精品美腿丝袜| 国内精品伊人久久久久影院对白| 99r精品视频| 欧美电影免费观看高清完整版在| 日本 国产 欧美色综合| 久久成人免费网站| 91丝袜国产在线播放| 日韩欧美一卡二卡| 亚洲另类在线制服丝袜| 国产在线日韩欧美| 欧美韩国日本不卡| 久久成人av少妇免费| 欧美体内she精高潮| 国产精品美女一区二区三区| 免费一区二区视频| 在线一区二区视频| 中文幕一区二区三区久久蜜桃| 青青草国产成人99久久| 色综合久久综合网欧美综合网| 欧美国产禁国产网站cc| 五月天激情综合| 日本特黄久久久高潮| 日韩欧美一二区| 高潮精品一区videoshd| 中文字幕一区二区三区乱码在线| 国产一区二区三区精品欧美日韩一区二区三区 | 日韩午夜av电影| 国产精品一区二区黑丝 | 26uuu精品一区二区| 美女脱光内衣内裤视频久久网站| 日韩一区二区电影网| 免费成人性网站| 久久精品一区四区| 菠萝蜜视频在线观看一区| 亚洲午夜久久久久久久久电影院| 欧美丰满嫩嫩电影| 精品一区二区三区的国产在线播放| 成年人网站91| 蜜臀久久99精品久久久久宅男 |