Biblioteca Java - Blame information for rev 8
Subversion Repositories:
Rev | Author | Line No. | Line |
---|---|---|---|
8 | mihai | 1 | package timer1; |
2 | |||
3 | import java.util.Timer; | ||
4 | import java.util.TimerTask; | ||
5 | |||
6 | /** | ||
7 | * Simple demo that uses java.util.Timer to schedule a task | ||
8 | * to execute once 5 seconds have passed. | ||
9 | */ | ||
10 | |||
11 | public class Reminder { | ||
12 | Timer timer; | ||
13 | |||
14 | public Reminder(int seconds) { | ||
15 | timer = new Timer(); | ||
16 | timer.schedule(new RemindTask(), seconds*1000); | ||
17 | } | ||
18 | |||
19 | class RemindTask extends TimerTask { | ||
20 | public void run() { | ||
21 | System.out.format("Time's up!%n"); | ||
22 | timer.cancel(); //Terminate the timer thread | ||
23 | } | ||
24 | } | ||
25 | |||
26 | public static void main(String args[]) { | ||
27 | new Reminder(5); | ||
28 | System.out.format("Task scheduled.%n"); | ||
29 | } | ||
30 | } |