Skip to content

Commit 0b3df48

Browse files
RenjithkannathAlexander Zvegintsev
authored andcommitted
8372048: Performance improvement on Linux remote desktop
Reviewed-by: azvegint, serb
1 parent d2926df commit 0b3df48

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/java.desktop/unix/classes/sun/awt/screencast/ScreencastHelper.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ public final class ScreencastHelper {
6363
private static final int DELAY_BEFORE_SESSION_CLOSE = 2000;
6464

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

67+
private static class TimerHolder {
68+
private static final Timer timerCloseSession =
69+
new Timer("auto-close screencast session", true);
70+
}
6971

7072
private ScreencastHelper() {}
7173

@@ -143,7 +145,7 @@ public void run() {
143145
}
144146
};
145147

146-
timerCloseSession.schedule(timerTask, DELAY_BEFORE_SESSION_CLOSE);
148+
TimerHolder.timerCloseSession.schedule(timerTask, DELAY_BEFORE_SESSION_CLOSE);
147149
}
148150

149151
public static synchronized void getRGBPixels(

src/java.desktop/unix/classes/sun/awt/screencast/TokenStorage.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ public void run() {
238238
}
239239

240240
private static WatchService watchService;
241+
private static volatile boolean isWatcherThreadStarted = false;
241242

242243
private static void setupWatch() {
243244
try {
@@ -257,10 +258,6 @@ private static void setupWatch() {
257258
"file watch %s\n", e);
258259
}
259260
}
260-
261-
if (watchService != null) {
262-
new WatcherThread(watchService).start();
263-
}
264261
}
265262

266263
// called from native
@@ -337,7 +334,27 @@ private static boolean readTokens(Path path) {
337334
return true;
338335
}
339336

337+
private static void startWatcherThreadIfNeeded() {
338+
if (!isWatcherThreadStarted) {
339+
// not sure if the double-checked locking is actually needed here
340+
// the getTokens is only called from ScreencastHelper#getRGBPixels
341+
// and ScreencastHelper#remoteDesktop* methods (which are synchronized),
342+
// but it may change later.
343+
synchronized (TokenStorage.class) {
344+
if (!isWatcherThreadStarted) {
345+
readTokens(PROPS_PATH);
346+
if (watchService != null) {
347+
new WatcherThread(watchService).start();
348+
}
349+
isWatcherThreadStarted = true;
350+
}
351+
}
352+
}
353+
}
354+
340355
static Set<TokenItem> getTokens(List<Rectangle> affectedScreenBounds) {
356+
startWatcherThreadIfNeeded();
357+
341358
// We need an ordered set to store tokens
342359
// with exact matches at the beginning.
343360
LinkedHashSet<TokenItem> result = new LinkedHashSet<>();

0 commit comments

Comments
 (0)