Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
8176499: Dependence on java.util.Timer freezes screen when OS time re…
…sets backwards
Reviewed-by: jvos
- Loading branch information
|
@@ -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; |
|
|
} |
|
|
} |
|
|