timer purge_Java Timer purge()方法與示例

timer purge

計時器類purge()方法 (Timer Class purge() method)

  • purge() method is available in java.util package.

    purge()方法在java.util包中可用。

  • purge() method is used to remove all canceled tasks from the task queue of this Timer.

    purge()方法用于從此Timer的任務隊列中刪除所有已取消的任務。

  • purge() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    purge()方法是一種非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • purge() method does not throw an exception at the time of canceling task.

    purge()方法在取消任務時不會引發異常。

Syntax:

句法:

    public int purge();

Parameter(s):

參數:

  • It does not accept any parameter.

    它不接受任何參數。

Return value:

返回值:

The return type of the method is int, it returns the removed cancelled task from the queue.

方法的返回類型為int ,它從隊列中返回已刪除的已取消任務。

Example:

例:

// Java program to demonstrate the example 
// of int purge() method of Timer
import java.util.*;
class CancelTimer extends TimerTask {
// Task defined in this method
public void run() {
System.out.println("In Stock...Stop Working");
}
}
public class PurgeOfTimer {
public static void main(String[] args) {
// Instantaites a TimerTask and
// Timer object
TimerTask task = new CancelTimer();
Timer tmr = new Timer();
// By using scheduleAtFixedRate() method isto
// schedule the task at a constant rate in a
// repeated manner
tmr.scheduleAtFixedRate(task, new Date(), 330);
// By using cancel() method is to
// cancel this timer and stop
// the scheduled task
System.out.println("tmr.cancel(): " + "Cancelled");
tmr.cancel();
// By using purge() method is to
// remove cancelled from the task
// list
System.out.println("tmr.purge(): " + tmr.purge());
}
}

Output

輸出量

tmr.cancel(): Cancelled
In Stock...Stop Working
tmr.purge(): 0

翻譯自: https://www.includehelp.com/java/timer-purge-method-with-example.aspx

timer purge

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/540979.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/540979.shtml
英文地址,請注明出處:http://en.pswp.cn/news/540979.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

大話Linux內核中鎖機制之原子操作、自旋鎖【轉】

轉自:http://blog.sina.com.cn/s/blog_6d7fa49b01014q7p.html 多人會問這樣的問題,Linux內核中提供了各式各樣的同步鎖機制到底有何作用?追根到底其實是由于操作系統中存在多進程對共享資源的并發訪問,從而引起了進程間的競態。這…

hashmap put方法_Java HashMap put()方法與示例

hashmap put方法HashMap類的put()方法 (HashMap Class put() method) put() method is available in java.util package. put()方法在java.util包中可用。 put() method is used to link the given value element with the given key element in this HashMap. put()方法用于在…

java中jdom,java – JDOM中的命名空間(默認)

我正在嘗試使用最新的JDOM包生成XML文檔.我遇到了根元素和命名空間的問題.我需要生成這個根元素:xmlns"http://www.energystar.gov/manageBldgs/req"xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation"http://www.…

java enummap_Java EnumMap get()方法與示例

java enummapEnumMap類的get()方法 (EnumMap Class get() method) get() method is available in java.util package. get()方法在java.util包中可用。 get() method is used to get the value mapped with the given key element (key_ele) otherwise it returns null when no…

java后臺json傳遞,后臺json傳遞

json除了可以用于前臺傳遞,還可用于后臺之間傳遞。它可以傳遞List,Map,Bean等類型的數據。例如:User u1new User();u1.setUsername("zy");u1.setPassword("123");User u2new User();u2.setUsername("msl");u2.setPassword…

專家呼吁建安全漏洞信息共享機制并強化管控

近日,由中國網絡空間安全協會主辦,中國網絡空間安全協會網絡空間安全法律與公共政策專業委員會、北京郵電大學互聯網治理與法律研究中心、公安部第三研究所網絡安全法律研究中心、西安交通大學信息安全法律研究中心承辦的《網絡安全法(草案二…

java的equals方法_Java Date equals()方法與示例

java的equals方法日期類equals()方法 (Date Class equals() method) equals() method is available in java.util package. equals()方法在java.util包中可用。 equals() method is used to check whether this date and the given object (o) are equals or not. equals()方法…

lnmp解析php,LNMP之 php解析

[rootLNMP ~]# vim /usr/local/nginx/conf/nginx.conf打開以下PHP 相關項且更改 scripts$fastcgi_script_name;> /usrlocal/nginx/html$fastcgi_script_name;location ~ \.php$ {root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param…

spring歷史背景

1.2004年spring出現第一版本spring frameworl1.0 2.寫代碼永遠是最簡單的,后續的運維工作才是讓人感到無助的 3.spring boot在運維方面做了很多工作,部署,監控,度量。結合spring cloud還可以實現服務發現,服務降級等功…

計算機網絡中的傳輸協議是_計算機網絡中的傳輸方式

計算機網絡中的傳輸協議是傳輸方式 (Transmission Modes) The mechanism of transferring data or information between two linked devices connected over a network is referred to as Transmission Modes. 在通過網絡連接的兩個鏈接的設備之間傳輸數據或信息的機制稱為傳輸…

https 密鑰 php,https加密方式是什么

Https加密介紹Http直接通過明文在瀏覽器和服務器之間傳遞消息,容易被監聽抓取到通信內容。Https采用對稱加密和非對稱加密結合的方式來進行通信。Https不是應用層的新協議,而是Http通信接口用SSL和TLS來加強加密和認證機制。加密方式對稱加密&#xff1a…

一個前端框架應該有的一些公共函數

一、防止ie瀏覽器按backspace回退頁面 //防止后退返回頁面,如果非文本框、密碼框、文本域控件,或控件非可用裝填,則禁用后退按鍵 var uanavigator.userAgent.toLowerCase(); var isIEua.indexOf("msie")>-1; window.document.onkeydown fu…

Kruskal(P)和Prim(K)算法

最小生成樹 (Minimum Spanning Tree) An MST is a subset of the edges of the connected, undirected graph that connect all the vertices together, in which there is no forming of a cycle and there should be minimum possible total edge weight. MST是已連接的無向圖…

java get post 注解,GET/POST接收或發送數據的問題

在文章開始,先來回憶一下GET、POST這兩種請求方式的區別。?Http定義了與服務器交互的不同方法,最基本的方法有4種,分別是GET,POST,PUT,DELETE。URL全稱是資源描述符,我們可以這樣認為&#xff…

mybatis中sql語句傳入多個參數方法

1 使用map <select id"selectRole" parameterType"map" resultType"RoleMap">SELECT id, roleName, noteFROM roleWHERE roleName LIKE Concat(%,#{roleName},%)and note like Concat(%,#{note},%)</select> 在接口中如下定義 List&…

kotlin半生對象_Kotlin程序| 隨播對象特征

kotlin半生對象伴侶對象 (Companion object) If you need a function or a property to be tied to a class rather than to instances of it (similar to static in java), you can declare it inside a companion object: 如果需要將函數或屬性綁定到類而不是實例(類似于java…

mysql安裝注意步驟,mysql安裝步驟

mysql安裝步驟1、在官網下載對應的壓縮文件&#xff0c;放到本地文件夾下&#xff0c;解壓縮。2、配置Path環境變量&#xff1a;新增mysql的bin文件夾路徑&#xff0c;C:\software\mysql-8.0.23-winx64\bin。3、在mysql根目錄下新增my.ini配置文件。內容如下&#xff0c;basedi…

maven插件介紹之tomcat7-maven-plugin

tomcat7-maven-plugin插件的pom.xml依賴為&#xff1a; <dependency><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><version>2.2</version> </dependency>一&#xff1a;直接執行…

在Python中模擬do-while循環

Python as a language doesnt support the do-while loop. However, we can have a workaround to emulate the do-while loop. Python作為一種語言不支持do-while循環。 但是&#xff0c;我們可以采用一種變通方法來模擬do-while循環 。 The syntax for do-while is as follo…

織夢cms生成首頁html的php文件,織夢DedeCMS定時自動生成首頁HTML的實現方法

只需要制作一個文件然后在首頁模板添加一句代碼就可以實現讓織夢DedeCMS自動生成首頁html&#xff0c;具體方法如下&#xff1a;第一步、需要在首頁調用隨機文章&#xff0c;這樣每次自動更新才會有更新的效果&#xff0c;隨機文章調用標簽如下&#xff1a;{dede:arclist sortr…