Skip to content

Commit 1cae6a8

Browse files
dellgreenJohan Vos
authored and
Johan Vos
committed
8176499: Dependence on java.util.Timer freezes screen when OS time resets backwards
Reviewed-by: jvos
1 parent 2b9eb52 commit 1cae6a8

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/MonocleTimer.java

+9-14
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@
2626
package com.sun.glass.ui.monocle;
2727

2828
import com.sun.glass.ui.Timer;
29+
import java.util.concurrent.ScheduledFuture;
30+
import java.util.concurrent.ScheduledThreadPoolExecutor;
31+
import java.util.concurrent.TimeUnit;
2932

3033
/**
3134
* Monocle implementation class for Timer.
3235
*/
3336
final class MonocleTimer extends Timer {
34-
private static java.util.Timer timer;
35-
private java.util.TimerTask task;
37+
private static ScheduledThreadPoolExecutor scheduler;
38+
private ScheduledFuture<?> task;
3639

3740
MonocleTimer(final Runnable runnable) {
3841
super(runnable);
@@ -47,19 +50,11 @@ static int getMaxPeriod_impl() {
4750
}
4851

4952
@Override protected long _start(final Runnable runnable, int period) {
50-
if (timer == null) {
51-
timer = new java.util.Timer(true);
53+
if (scheduler == null) {
54+
scheduler = new ScheduledThreadPoolExecutor(1);
5255
}
5356

54-
task = new java.util.TimerTask() {
55-
56-
@Override
57-
public void run() {
58-
runnable.run();
59-
}
60-
};
61-
62-
timer.schedule(task, 0, (long)period);
57+
task = scheduler.scheduleAtFixedRate(runnable, 0, period, TimeUnit.MILLISECONDS);
6358
return 1; // need something non-zero to denote success.
6459
}
6560

@@ -69,7 +64,7 @@ public void run() {
6964

7065
@Override protected void _stop(long timer) {
7166
if (task != null) {
72-
task.cancel();
67+
task.cancel(false);
7368
task = null;
7469
}
7570
}

0 commit comments

Comments
 (0)