Java Timer: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 16: Line 16:
</blockquote>
</blockquote>


This is the <tt>java.util.TimerThread</tt> implementation details:
This is the <tt>java.util.TimerThread</tt> implementation detail:


<pre>
<pre>

Revision as of 22:12, 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) {
            }
        }
    }
   ...
}