Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 1cae6a8
Showing 1 changed file with 9 additions and 14 deletions.
Expand Up @@ -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);
Expand All @@ -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.
}

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

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

0 comments on commit 1cae6a8

Please sign in to comment.