-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTimer.java
More file actions
46 lines (36 loc) · 1.16 KB
/
Timer.java
File metadata and controls
46 lines (36 loc) · 1.16 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
package contention.benchmark.workload.stop.condition;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicBoolean;
import static contention.benchmark.tools.StringFormat.indentedTitleWithData;
public class Timer implements StopCondition {
transient private AtomicBoolean stop;
public long workTime;
public Timer() {}
public Timer(long workTime) {
this.workTime = workTime;
}
public void setWorkTime(long workTime) {
this.workTime = workTime;
}
@Override
public void start(int numThreads) {
stop = new AtomicBoolean(false);
java.util.Timer timer = new java.util.Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
stop.set(true);
}
}, workTime);
}
@Override
public boolean isStopped(int id) {
return stop.get();
}
@Override
public StringBuilder toStringBuilder(int indents) {
return new StringBuilder()
.append(indentedTitleWithData("Type", "Timer", indents))
.append(indentedTitleWithData("Work time", workTime, indents));
}
}