Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ public final class ScreencastHelper {
private static final int DELAY_BEFORE_SESSION_CLOSE = 2000;

private static volatile TimerTask timerTask = null;
private static final Timer timerCloseSession
= new Timer("auto-close screencast session", true);

private static class TimerHolder {
private static final Timer timerCloseSession =
new Timer("auto-close screencast session", true);
}

private ScreencastHelper() {}

Expand Down Expand Up @@ -143,7 +145,7 @@ public void run() {
}
};

timerCloseSession.schedule(timerTask, DELAY_BEFORE_SESSION_CLOSE);
TimerHolder.timerCloseSession.schedule(timerTask, DELAY_BEFORE_SESSION_CLOSE);
}

public static synchronized void getRGBPixels(
Expand Down
25 changes: 21 additions & 4 deletions src/java.desktop/unix/classes/sun/awt/screencast/TokenStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ public void run() {
}

private static WatchService watchService;
private static volatile boolean isWatcherThreadStarted = false;

private static void setupWatch() {
try {
Expand All @@ -257,10 +258,6 @@ private static void setupWatch() {
"file watch %s\n", e);
}
}

if (watchService != null) {
new WatcherThread(watchService).start();
}
}

// called from native
Expand Down Expand Up @@ -337,7 +334,27 @@ private static boolean readTokens(Path path) {
return true;
}

private static void startWatcherThreadIfNeeded() {
if (!isWatcherThreadStarted) {
// not sure if the double-checked locking is actually needed here
// the getTokens is only called from ScreencastHelper#getRGBPixels
// and ScreencastHelper#remoteDesktop* methods (which are synchronized),
// but it may change later.
synchronized (TokenStorage.class) {
if (!isWatcherThreadStarted) {
readTokens(PROPS_PATH);
if (watchService != null) {
new WatcherThread(watchService).start();
}
isWatcherThreadStarted = true;
}
}
}
}

static Set<TokenItem> getTokens(List<Rectangle> affectedScreenBounds) {
startWatcherThreadIfNeeded();

// We need an ordered set to store tokens
// with exact matches at the beginning.
LinkedHashSet<TokenItem> result = new LinkedHashSet<>();
Expand Down