Biblioteca Java - Blame information for rev 3

Subversion Repositories:
Rev:
Rev Author Line No. Line
3 mihai 1 /*
2  * ScheduleTask.java
3  */
4 package lab.scd.fire.schedule;
5  
6 import java.util.Timer;
7 import java.util.TimerTask;
8  
9 /**
10  * Class created by @author Mihai HULEA at Feb 22, 2005.
11  *
12  * This class is part of the labs project.
13  *
14  * Programul exeplicfica utilizarea clasei Timer. Aceasat clasa permite planificarea
15  * taskurilor pentru executie. Taskurile pot fi periodice. Pentru a putea fi planificat
16  * pentru executie un task trebuie sa fie construit avand la baza clasa TimerTask.
17  *
18  * 1. Testati modul de functionare al programului
19  *
20  */
21 public class ScheduleTask {
22  
23     Timer timer = new Timer();
24  
25     public ScheduleTask() {
26  
27         timer.schedule(new RemindTask(),
28                        0,        //initial delay
29                        1*1000);  //subsequent rate
30  
31         timer.schedule( new SingleExecution(),2000);
32     }
33  
34     /**
35      * Task ce se va executa periodic.
36      * Class created by @author Mihai HULEA at Feb 22, 2005.
37      *
38      * This class is part of the labs project.
39      *
40      */
41     class RemindTask extends TimerTask {
42         int numWarningBeeps = 3;
43         public void run() {
44             if (numWarningBeeps > 0) {
45  
46                 System.out.println("Beep!");
47                 numWarningBeeps--;
48             } else {
49  
50                 System.out.println("Time's up!");
51  
52                 System.exit(0);  
53             }
54  
55     }
56     }
57  
58     /**
59      * Task ce se va executa o singura data.
60      * Class created by @author Mihai HULEA at Feb 22, 2005.
61      *
62      * This class is part of the labs project.
63      *
64      */
65     class SingleExecution extends TimerTask{
66         public void run(){
67             System.out.println("Task executed.");
68         }
69     }
70  
71     public static void main(String[] args){
72         new ScheduleTask();
73     }
74 }