Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>According to the <a href="http://java.sun.com/javase/6/docs/api/java/util/Timer.html" rel="noreferrer"><code>Timer</code></a> documentation, in Java 1.5 onwards, you should prefer the <a href="http://java.sun.com/javase/6/docs/api/java/util/concurrent/ScheduledThreadPoolExecutor.html" rel="noreferrer"><code>ScheduledThreadPoolExecutor</code></a> instead. (You may like to create this executor using <a href="http://java.sun.com/javase/6/docs/api/java/util/concurrent/Executors.html" rel="noreferrer"><code>Executors</code></a><code>.newSingleThreadScheduledExecutor()</code> for ease of use; it creates something much like a <code>Timer</code>.)</p> <p>The cool thing is, when you schedule a task (by calling <code>schedule()</code>), it returns a <a href="http://java.sun.com/javase/6/docs/api/java/util/concurrent/ScheduledFuture.html" rel="noreferrer"><code>ScheduledFuture</code></a> object. You can use this to cancel the scheduled task. You're then free to submit a new task with a different triggering time.</p> <p>ETA: The <code>Timer</code> documentation linked to doesn't say anything about <code>ScheduledThreadPoolExecutor</code>, however the <a href="http://openjdk.java.net/" rel="noreferrer">OpenJDK</a> version had this to say:</p> <blockquote> <p>Java 5.0 introduced the <code>java.util.concurrent</code> package and one of the concurrency utilities therein is the <code>ScheduledThreadPoolExecutor</code> which is a thread pool for repeatedly executing tasks at a given rate or delay. It is effectively a more versatile replacement for the <code>Timer</code>/<code>TimerTask</code> combination, as it allows multiple service threads, accepts various time units, and doesn't require subclassing <code>TimerTask</code> (just implement <code>Runnable</code>). Configuring <code>ScheduledThreadPoolExecutor</code> with one thread makes it equivalent to <code>Timer</code>.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload