Skip to content

Commit d90b608

Browse files
committed
[grid] Removing Regularly from HandleSession
1 parent a5ef564 commit d90b608

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

‎java/src/org/openqa/selenium/grid/router/HandleSession.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,21 @@
1717

1818
package org.openqa.selenium.grid.router;
1919

20+
import static org.openqa.selenium.remote.HttpSessionId.getSessionId;
21+
import static org.openqa.selenium.remote.RemoteTags.SESSION_ID;
22+
import static org.openqa.selenium.remote.RemoteTags.SESSION_ID_EVENT;
23+
import static org.openqa.selenium.remote.http.Contents.asJson;
24+
import static org.openqa.selenium.remote.tracing.Tags.EXCEPTION;
25+
import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST;
26+
import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST_EVENT;
27+
import static org.openqa.selenium.remote.tracing.Tags.HTTP_RESPONSE;
28+
2029
import com.google.common.cache.Cache;
2130
import com.google.common.cache.CacheBuilder;
2231
import com.google.common.cache.RemovalListener;
2332
import com.google.common.collect.ImmutableMap;
2433

2534
import org.openqa.selenium.NoSuchSessionException;
26-
import org.openqa.selenium.concurrent.Regularly;
2735
import org.openqa.selenium.grid.data.Session;
2836
import org.openqa.selenium.grid.sessionmap.SessionMap;
2937
import org.openqa.selenium.grid.web.ReverseProxyHandler;
@@ -47,15 +55,9 @@
4755
import java.util.HashMap;
4856
import java.util.Map;
4957
import java.util.concurrent.Callable;
50-
51-
import static org.openqa.selenium.remote.HttpSessionId.getSessionId;
52-
import static org.openqa.selenium.remote.RemoteTags.SESSION_ID;
53-
import static org.openqa.selenium.remote.RemoteTags.SESSION_ID_EVENT;
54-
import static org.openqa.selenium.remote.http.Contents.asJson;
55-
import static org.openqa.selenium.remote.tracing.Tags.EXCEPTION;
56-
import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST;
57-
import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST_EVENT;
58-
import static org.openqa.selenium.remote.tracing.Tags.HTTP_RESPONSE;
58+
import java.util.concurrent.Executors;
59+
import java.util.concurrent.ScheduledExecutorService;
60+
import java.util.concurrent.TimeUnit;
5961

6062
class HandleSession implements HttpHandler {
6163

@@ -77,8 +79,16 @@ class HandleSession implements HttpHandler {
7779
.removalListener((RemovalListener<URL, HttpClient>) removal -> removal.getValue().close())
7880
.build();
7981

80-
new Regularly("Clean up http clients cache").submit(
81-
httpClients::cleanUp, Duration.ofMinutes(1), Duration.ofMinutes(1));
82+
ScheduledExecutorService cleanUpHttpClientsCacheService =
83+
Executors.newSingleThreadScheduledExecutor(
84+
r -> {
85+
Thread thread = new Thread(r);
86+
thread.setDaemon(true);
87+
thread.setName("HandleSession - Clean up http clients cache");
88+
return thread;
89+
});
90+
cleanUpHttpClientsCacheService.scheduleAtFixedRate(
91+
httpClients::cleanUp, 1, 1, TimeUnit.MINUTES);
8292
}
8393

8494
@Override

0 commit comments

Comments
 (0)