亚洲欧美第一页_禁久久精品乱码_粉嫩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精品婷婷国产综合久久| 欧美日韩国产一区二区三区地区| 一区二区视频免费在线观看| 欧美美女黄视频| 成人性视频网站| 日韩成人av影视| 亚洲美女区一区| 国产日韩成人精品| 日韩欧美电影一区| 欧美日韩一区小说| 99免费精品在线| 国产美女娇喘av呻吟久久| 五月激情丁香一区二区三区| 国产精品护士白丝一区av| 久久嫩草精品久久久精品一| 欧美一区二区三区思思人| 在线观看91视频| av福利精品导航| 国产精品一区二区免费不卡| 麻豆91免费观看| 视频一区国产视频| 亚洲一区二区3| 玉米视频成人免费看| 1区2区3区欧美| 国产精品久久久久永久免费观看 | 亚洲国产日韩av| 亚洲欧美中日韩| 国产亚洲美州欧州综合国| 日韩欧美一二三区| 日韩三级电影网址| 日韩精品一区二区三区中文精品| 欧美视频一区在线| 欧美日韩国产不卡| 欧美日韩国产片| 欧美丰满少妇xxxxx高潮对白| 欧美色图12p| 欧美日韩大陆一区二区| 91麻豆精品国产91久久久久久| 在线观看免费一区| 欧美日韩视频在线观看一区二区三区 | 国产精品久久久久久久久晋中| 国产日韩高清在线| 国产精品国产精品国产专区不蜜| 国产精品三级在线观看| 中文字幕制服丝袜成人av| ...xxx性欧美| 亚洲精品乱码久久久久久日本蜜臀| 中文字幕在线一区二区三区| 亚洲精品乱码久久久久久久久| 亚洲一区在线看| 天天综合日日夜夜精品| 久久精品国产99国产| 国产伦精品一区二区三区视频青涩 | 日韩精品一区二区三区三区免费 | 国产成人精品三级| 成人午夜精品在线| 色噜噜狠狠一区二区三区果冻| 色哟哟国产精品免费观看| 欧美日韩一区二区三区四区五区| 欧美日韩国产在线观看| 亚洲精品一线二线三线| 日本一区二区成人| 一级中文字幕一区二区| 日韩国产欧美视频| 国产精品一区二区三区网站| 99久久精品国产麻豆演员表| 色婷婷激情一区二区三区| 欧美视频一区二区三区在线观看 | 日韩中文字幕av电影| 毛片基地黄久久久久久天堂| 成人夜色视频网站在线观看| 在线免费观看成人短视频| 欧美一区二区私人影院日本| 国产日韩精品久久久| 亚洲一区av在线| 黄页视频在线91| 色综合色狠狠天天综合色| 91精品国产美女浴室洗澡无遮挡| 久久久亚洲欧洲日产国码αv| 亚洲人成网站影音先锋播放| 久久激情五月婷婷| 91麻豆国产福利在线观看| 日韩一区二区高清| 国产精品色婷婷| 美洲天堂一区二卡三卡四卡视频 | 午夜在线成人av| 国产成人精品免费看| 欧美日本一道本| 国产日韩欧美高清在线| 亚洲成a人片综合在线| 成人小视频在线| 欧美一二三区在线观看| 亚洲免费视频中文字幕| 韩国精品免费视频| 欧美日韩一级片网站| 国产精品久久免费看| 久久99久久99精品免视看婷婷 | 777色狠狠一区二区三区| 国产性色一区二区| 日本成人在线一区| 在线精品亚洲一区二区不卡| 久久久久久亚洲综合| 日韩国产精品大片| 在线视频国内一区二区| 亚洲国产精品成人久久综合一区 | 播五月开心婷婷综合| 日韩美女主播在线视频一区二区三区| 17c精品麻豆一区二区免费| 久久精品国产一区二区三区免费看 | 一区二区三区四区激情 | 色哟哟一区二区三区| 国产日韩在线不卡| 看片网站欧美日韩| 91超碰这里只有精品国产| 亚洲裸体在线观看| 国产成人aaa| 久久久久综合网| 精品在线观看视频| 欧美一区二区免费观在线| 亚洲成人免费av| 在线精品视频一区二区三四| 亚洲精品老司机| 色综合激情久久| 亚洲女女做受ⅹxx高潮| av激情综合网| 中文字幕中文字幕中文字幕亚洲无线| 国产精品影音先锋| 久久精品男人天堂av| 精品一区二区三区久久久| 51精品国自产在线| 首页国产丝袜综合| 666欧美在线视频| 日韩高清不卡一区二区| 91精品在线观看入口| 美女视频一区在线观看| 日韩一区二区视频| 精品一区中文字幕| 精品99久久久久久| 国产精品一区久久久久| 久久久久久日产精品| 成人一区二区视频| 自拍偷拍欧美精品| 欧美中文字幕一二三区视频| 亚洲最大的成人av| 欧美疯狂性受xxxxx喷水图片| 日韩av网站免费在线| 日韩一区二区三区免费看| 久久99久久精品| 国产精品全国免费观看高清| 99re6这里只有精品视频在线观看| 亚洲三级视频在线观看| 欧美中文字幕不卡| 久久精品国产99| 欧美激情综合五月色丁香小说| 99在线精品观看| 亚洲成av人片一区二区三区| 日韩一区二区三区电影在线观看| 麻豆精品在线视频| 国产精品丝袜一区| 欧洲国内综合视频| 紧缚捆绑精品一区二区| 中文字幕不卡的av| 91久久久免费一区二区| 亚洲午夜私人影院| 日韩精品一区二区三区视频| 成人免费福利片| 亚洲成人高清在线| 久久久国际精品| 91久久一区二区| 久久99在线观看| 日韩一区中文字幕| 这里是久久伊人| 粉嫩av一区二区三区在线播放 | 综合电影一区二区三区| 欧美二区在线观看| 国产盗摄女厕一区二区三区| 亚洲精品久久久蜜桃| 精品久久免费看| 色猫猫国产区一区二在线视频| 奇米精品一区二区三区在线观看 | 欧美一级黄色片| 成人av网站在线| 婷婷开心激情综合| 国产精品网站在线| 91精品久久久久久蜜臀| 成人激情电影免费在线观看| 亚洲国产成人91porn| 国产精品久久久久久久久快鸭 | 欧美哺乳videos| 91黄色在线观看| 国产乱码字幕精品高清av| 亚洲国产综合视频在线观看| 国产欧美日韩不卡免费| 欧美一区二区三区免费| 91黄视频在线观看| 成人成人成人在线视频| 久久精品国产一区二区三| 亚洲午夜国产一区99re久久| 中文字幕第一区二区| 精品国产髙清在线看国产毛片|