Timer.java
825 Bytes
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
package org.onlab.util;
import org.jboss.netty.util.HashedWheelTimer;
/**
* Hashed-wheel timer singleton. Care must be taken to shutdown the timer
* only when the VM is ready to exit.
*/
public final class Timer {
private static volatile HashedWheelTimer timer;
// Ban public construction
private Timer() {
}
/**
* Returns the singleton hashed-wheel timer.
*
* @return hashed-wheel timer
*/
public static HashedWheelTimer getTimer() {
if (Timer.timer == null) {
initTimer();
}
return Timer.timer;
}
private static synchronized void initTimer() {
if (Timer.timer == null) {
HashedWheelTimer hwTimer = new HashedWheelTimer();
hwTimer.start();
Timer.timer = hwTimer;
}
}
}