Skip to content

Commit

Permalink
[grid] shutdown executors created for a single tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
joerg1985 committed Sep 30, 2023
1 parent c34fc94 commit 0b5cf2d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
Expand Up @@ -45,6 +45,7 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -379,8 +380,9 @@ private void updateNodeStatus(NodeStatus status, Runnable healthCheck) {
.build();

LOG.log(getDebugLogLevel(), "Running health check for Node " + status.getExternalUri());
Executors.newSingleThreadExecutor()
.submit(() -> Failsafe.with(initialHealthCheckPolicy).run(healthCheck::run));
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(() -> Failsafe.with(initialHealthCheckPolicy).run(healthCheck::run));
executor.shutdown();
}
}

Expand Down
40 changes: 21 additions & 19 deletions java/src/org/openqa/selenium/grid/node/httpd/NodeServer.java
Expand Up @@ -32,6 +32,7 @@
import dev.failsafe.RetryPolicy;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
Expand Down Expand Up @@ -200,25 +201,26 @@ public NettyServer start() {
.build();

LOG.info("Starting registration process for Node " + node.getUri());
Executors.newSingleThreadExecutor()
.submit(
() -> {
Failsafe.with(registrationPolicy)
.run(
() -> {
if (nodeRegistered.get()) {
throw new InterruptedException("Stopping registration thread.");
}
HealthCheck.Result check = node.getHealthCheck().check();
if (DOWN.equals(check.getAvailability())) {
LOG.severe("Node is not alive: " + check.getMessage());
// Throw an exception to force another check sooner.
throw new UnsupportedOperationException("Node cannot be registered");
}
bus.fire(new NodeStatusEvent(node.getStatus()));
LOG.info("Sending registration event...");
});
});
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(
() -> {
Failsafe.with(registrationPolicy)
.run(
() -> {
if (nodeRegistered.get()) {
throw new InterruptedException("Stopping registration thread.");
}
HealthCheck.Result check = node.getHealthCheck().check();
if (DOWN.equals(check.getAvailability())) {
LOG.severe("Node is not alive: " + check.getMessage());
// Throw an exception to force another check sooner.
throw new UnsupportedOperationException("Node cannot be registered");
}
bus.fire(new NodeStatusEvent(node.getStatus()));
LOG.info("Sending registration event...");
});
});
executor.shutdown();

return this;
}
Expand Down

0 comments on commit 0b5cf2d

Please sign in to comment.