-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTimerTaskCannotReschedule.java
More file actions
59 lines (42 loc) · 1.55 KB
/
TimerTaskCannotReschedule.java
File metadata and controls
59 lines (42 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.TimerTask;
import specification.Borrowed;
import specification.Free;
public class SSSTimerTaskCannotReschedule {
/*
* Error cannot reschedule a timer
*/
public static void example1801324_simplified( @Borrowed Timer timer, String sessionKey, @Free TimerTask tt) {
// Step 2) Cancel the timer
timer.cancel();
// Step 3 Schedule a new task for this timer -> ERROR Cannot reschedule a Timer
timer.schedule(tt , 1000);
}
}
/*
* [If the timer is cancelled] any further attempt to schedule a task on the timer will result in an IllegalStateException
*
* START --- schedule() ----> [SCHEDULED]-------->
* ----------------------------------------> cancel() -----> [CANCELLED] (no further scheduling allowed)
*/
class Timer{
//@StateRefinement(this, to="cancelled")
public void cancel() { }
// @StateRefinement(this, from="start", to="scheduled")
public void schedule(TimerTask task, /* delay > 0 */int delay) {}
}
// /*
// * Error cannot reschedule a timer
// */
// public static void example1801324( Map<String, Timer> timers, String sessionKey) {
// // Step 1) Get the timer
// Timer timer = timers.get(sessionKey);
// // Step 2) Cancel the timer
// timer.cancel();
// // Step 3) Schedule a new task for this timer -> ERROR Cannot reschedule a Timer
// timer.schedule(new TimerTask() {
// @Override
// public void run() {
// System.out.println("Timer task completed.");
// }
// }, 1000);
// }