Skip to content

Commit

Permalink
[SPARK-46717][CORE] Simplify ReloadingX509TrustManager by the exit …
Browse files Browse the repository at this point in the history
…operation only depend on interrupt thread

### What changes were proposed in this pull request?
This PR propose to simplify the `ReloadingX509TrustManager`.

### Why are the changes needed?
Currently, close or destroy `ReloadingX509TrustManager` depend on interrupt thread and the volatile variable `running`.
In fact, we can change the `running` to a local variable on stack and let the close operation of `ReloadingX509TrustManager` only depend on interrupt thread.

### Does this PR introduce _any_ user-facing change?
'No'.

### How was this patch tested?
GA tests.

### Was this patch authored or co-authored using generative AI tooling?
'No'.

Closes #44720 from beliefer/simplify-ReloadingX509TrustManager.

Authored-by: beliefer <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
  • Loading branch information
beliefer authored and dongjoon-hyun committed Jan 15, 2024
1 parent 4207cbe commit de79388
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public final class ReloadingX509TrustManager
protected volatile int needsReloadCheckCounts;
private final AtomicReference<X509TrustManager> trustManagerRef;

private volatile boolean running;
private Thread reloader;

/**
Expand Down Expand Up @@ -98,15 +97,13 @@ public ReloadingX509TrustManager(
public void init() {
reloader = new Thread(this, "Truststore reloader thread");
reloader.setDaemon(true);
running = true;
reloader.start();
}

/**
* Stops the reloader thread.
*/
public void destroy() throws InterruptedException {
running = false;
reloader.interrupt();
reloader.join();
}
Expand Down Expand Up @@ -200,11 +197,12 @@ X509TrustManager loadTrustManager()

@Override
public void run() {
boolean running = true;
while (running) {
try {
Thread.sleep(reloadInterval);
} catch (InterruptedException e) {
//NOP
running = false;
}
try {
if (running && needsReload()) {
Expand Down

0 comments on commit de79388

Please sign in to comment.