Skip to content
Permalink
Browse files

8176499: Dependence on java.util.Timer freezes screen when OS time re…

…sets backwards

Reviewed-by: jvos
  • Loading branch information
dellgreen authored and Johan Vos committed May 1, 2020
1 parent 2b9eb52 commit 1cae6a87a8322abf96e56853fc8d205723439e42
Showing with 9 additions and 14 deletions.
  1. +9 −14 modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/MonocleTimer.java
@@ -26,13 +26,16 @@
package com.sun.glass.ui.monocle;

import com.sun.glass.ui.Timer;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
* Monocle implementation class for Timer.
*/
final class MonocleTimer extends Timer {
private static java.util.Timer timer;
private java.util.TimerTask task;
private static ScheduledThreadPoolExecutor scheduler;
private ScheduledFuture<?> task;

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

@Override protected long _start(final Runnable runnable, int period) {
if (timer == null) {
timer = new java.util.Timer(true);
if (scheduler == null) {
scheduler = new ScheduledThreadPoolExecutor(1);
}

task = new java.util.TimerTask() {

@Override
public void run() {
runnable.run();
}
};

timer.schedule(task, 0, (long)period);
task = scheduler.scheduleAtFixedRate(runnable, 0, period, TimeUnit.MILLISECONDS);
return 1; // need something non-zero to denote success.
}

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

@Override protected void _stop(long timer) {
if (task != null) {
task.cancel();
task.cancel(false);
task = null;
}
}

0 comments on commit 1cae6a8

Please sign in to comment.