-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaTimer.java
More file actions
29 lines (27 loc) · 922 Bytes
/
JavaTimer.java
File metadata and controls
29 lines (27 loc) · 922 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
import java.util.Timer;
import java.util.TimerTask;
import java.lang.reflect.Method;
public class JavaTimer {
public Timer timer;
public JavaTimer(long ms, Object obj, String methodName, String[] paramTypes, Object[] params) {
try {
timer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
try {
Method method = Callback.getMethod(methodName, obj, paramTypes);
Callback cb = new Callback(method, obj, params);
cb.invoke();
} catch (Exception e) {
e.printStackTrace();
}
timer.cancel();
}
};
timer.schedule(task, ms, 1);
} catch (Exception e) {
e.printStackTrace();
}
}
}