Skip to content

Commit 960e168

Browse files
committed
[grid] Improving concurrency session creation by not having a unique instance
1 parent dfa7c79 commit 960e168

File tree

3 files changed

+36
-37
lines changed

3 files changed

+36
-37
lines changed

java/client/src/org/openqa/selenium/remote/service/DriverCommandExecutor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
public class DriverCommandExecutor extends HttpCommandExecutor implements Closeable {
4848

4949
private final DriverService service;
50-
private static final ExecutorService executorService = Executors.newFixedThreadPool(2, r -> {
50+
private final ExecutorService executorService = Executors.newFixedThreadPool(2, r -> {
5151
Thread thread = new Thread(r);
5252
thread.setName("Driver Command Executor");
5353
thread.setDaemon(true);

java/client/src/org/openqa/selenium/remote/service/DriverService.java

+34-35
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
package org.openqa.selenium.remote.service;
1919

20-
import static java.util.Collections.emptyMap;
21-
import static java.util.concurrent.TimeUnit.SECONDS;
22-
2320
import com.google.common.collect.ImmutableMap;
2421

2522
import org.openqa.selenium.Beta;
@@ -49,6 +46,9 @@
4946
import java.util.concurrent.TimeoutException;
5047
import java.util.concurrent.locks.ReentrantLock;
5148

49+
import static java.util.Collections.emptyMap;
50+
import static java.util.concurrent.TimeUnit.SECONDS;
51+
5252
/**
5353
* Manages the life and death of a native executable driver server.
5454
*
@@ -59,8 +59,9 @@
5959
* used to stop the server.
6060
*/
6161
public class DriverService implements Closeable {
62+
6263
protected static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(20);
63-
private static final ExecutorService executorService = Executors.newFixedThreadPool(2, r -> {
64+
private final ExecutorService executorService = Executors.newFixedThreadPool(2, r -> {
6465
Thread thread = new Thread(r);
6566
thread.setName("Driver Service Executor");
6667
thread.setDaemon(true);
@@ -77,17 +78,15 @@ public class DriverService implements Closeable {
7778
* Controls access to {@link #process}.
7879
*/
7980
private final ReentrantLock lock = new ReentrantLock();
80-
81+
private final String executable;
82+
private final Duration timeout;
83+
private final List<String> args;
84+
private final Map<String, String> environment;
8185
/**
8286
* A reference to the current child process. Will be {@code null} whenever this service is not
8387
* running. Protected by {@link #lock}.
8488
*/
8589
protected CommandLine process = null;
86-
87-
private final String executable;
88-
private final Duration timeout;
89-
private final List<String> args;
90-
private final Map<String, String> environment;
9190
private OutputStream outputStream = System.err;
9291

9392
/**
@@ -113,25 +112,6 @@ protected DriverService(
113112
this.url = getUrl(port);
114113
}
115114

116-
protected List<String> getArgs() {
117-
return args;
118-
}
119-
120-
protected Map<String, String> getEnvironment() {
121-
return environment;
122-
}
123-
124-
protected URL getUrl(int port) throws IOException {
125-
return new URL(String.format("http://localhost:%d", port));
126-
}
127-
128-
/**
129-
* @return The base URL for the managed driver server.
130-
*/
131-
public URL getUrl() {
132-
return url;
133-
}
134-
135115
/**
136116
*
137117
* @param exeName Name of the executable file to look for in PATH
@@ -165,6 +145,25 @@ protected static void checkExecutable(File exe) {
165145
Require.stateCondition(exe.canExecute(), "It must be an executable file: %s", exe);
166146
}
167147

148+
protected List<String> getArgs() {
149+
return args;
150+
}
151+
152+
protected Map<String, String> getEnvironment() {
153+
return environment;
154+
}
155+
156+
protected URL getUrl(int port) throws IOException {
157+
return new URL(String.format("http://localhost:%d", port));
158+
}
159+
160+
/**
161+
* @return The base URL for the managed driver server.
162+
*/
163+
public URL getUrl() {
164+
return url;
165+
}
166+
168167
/**
169168
* Checks whether the driver child process is currently running.
170169
*
@@ -181,12 +180,6 @@ public boolean isRunning() {
181180
}
182181
}
183182

184-
private enum StartOrDie {
185-
SERVER_STARTED,
186-
PROCESS_IS_ACTIVE,
187-
PROCESS_DIED
188-
}
189-
190183
/**
191184
* Starts this service if it is not already running. This method will block until the server has
192185
* been fully started and is ready to handle commands.
@@ -317,6 +310,12 @@ public void close() {
317310
executorService.shutdownNow();
318311
}
319312

313+
private enum StartOrDie {
314+
SERVER_STARTED,
315+
PROCESS_IS_ACTIVE,
316+
PROCESS_DIED
317+
}
318+
320319
public abstract static class Builder<DS extends DriverService, B extends Builder<?, ?>> {
321320

322321
private int port = 0;

java/server/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.openqa.selenium.grid.distributor.local;
1919

2020
import com.google.common.collect.ImmutableSet;
21+
2122
import org.openqa.selenium.Beta;
2223
import org.openqa.selenium.Capabilities;
2324
import org.openqa.selenium.ImmutableCapabilities;
@@ -58,7 +59,6 @@
5859
import org.openqa.selenium.grid.sessionmap.config.SessionMapOptions;
5960
import org.openqa.selenium.grid.sessionqueue.NewSessionQueue;
6061
import org.openqa.selenium.grid.sessionqueue.config.NewSessionQueueOptions;
61-
import org.openqa.selenium.internal.Debug;
6262
import org.openqa.selenium.internal.Either;
6363
import org.openqa.selenium.internal.Require;
6464
import org.openqa.selenium.remote.SessionId;

0 commit comments

Comments
 (0)