Java Timer: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
No edit summary
Line 11: 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.
<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>

Revision as of 02:46, 31 July 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.

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