Java Timer: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 2: Line 2:


* https://docs.oracle.com/javase/8/docs/api/java/util/Timer.html
* https://docs.oracle.com/javase/8/docs/api/java/util/Timer.html
* https://docs.oracle.com/javase/8/docs/api/java/util/TimerTask.html


=Internal=
=Internal=
Line 10: Line 11:


The Java <tt>java.util.Timer</tt> allows a task to be scheduled for execution at a specified time, or with a fixed delay, or at a fixed rate.
The Java <tt>java.util.Timer</tt> allows a task to be scheduled for execution at a specified time, or with a fixed delay, or at a fixed rate.
<blockquote style="background-color: Gold; border: solid thin Goldenrod;">
:<br>Note that if the <tt>TimerTask.run()</tt> implementation throws an unchecked exception, the Timer is canceled - there is no try/catch logic inside the timer's main loop.<br><br>
</blockquote>
This is the <tt>java.util.TimerThread</tt> implementation detail:
<pre>
class TimerThread extends Thread {
    ...
    private void mainLoop() {
        while (true) {
            try {
                ...
                if (taskFired)  // Task fired; run it, holding no locks
                    task.run();
            } catch(InterruptedException e) {
            }
        }
    }
  ...
}
</pre>
=scheduleAtFixedRate()=
<font color=red>TODO</font>

Latest revision as of 22:14, 26 October 2016

External

Internal

Overview

The Java java.util.Timer allows a task to be scheduled for execution at a specified time, or with a fixed delay, or at a fixed rate.


Note that if the TimerTask.run() implementation throws an unchecked exception, the Timer is canceled - there is no try/catch logic inside the timer's main loop.

This is the java.util.TimerThread implementation detail:

class TimerThread extends Thread {
    ...
    private void mainLoop() {
        while (true) {
            try {
                ...
                if (taskFired)  // Task fired; run it, holding no locks
                    task.run();
            } catch(InterruptedException e) {
            }
        }
    }
   ...
}

scheduleAtFixedRate()

TODO